2016-12-26 3 views
0

In my other question 사용자 계정 유형을 결정하는 방법을 묻습니다. 그러나 이제는 내가 가질 수있는 그룹의 종류를 발견해야합니다.그룹 유형을 결정하는 방법은 무엇입니까?

사용자를 그룹에 추가하는 함수를 작성하고 있습니다. 문제는 사용자를 추가하기 전에 그룹의 종류를 알아야한다는 것입니다. 보통 o365 그룹, 보안 그룹, 메일 그룹 또는 메일 사용 가능 보안 그룹 일 수 있습니다.

function GetGroupType([string]$groupname){ 
    #You can use get-group on any group, but the 'grouptype' results are not very descriptive 
    #mesg = "Universal, SecurityEnabled" 
    #o365 = "Universal" 
    #Distribution = "Universal" 
    $thisgrouptype = get-group -identity $groupname -ErrorAction SilentlyContinue | select grouptype 
    if($thisgrouptype.contains("Universal"){ 
     if($thisgrouptype.contains("SecurityEnabled"){ 
      $grouptype = "mesg" 
     }else{ 
      #since you can't run get-unifiedgroup against a security/distribution group, we should get "Universal" for the return value 
      $thisgrouptype = get-unifiedgroup -identity $groupname -ErrorAction SilentlyContinue | select grouptype 
      if($thisgrouptype -eq "Universal"){ 
       $grouptype = "o365" 
      }else{ 
      $grouptype = "distribution" 
     } 
    }else{ #if it doesn't have "Universal" then it's not what we are looking for 
     $grouptype = "" 
    } 

    return $grouptype 
} 

    #try to add a user to a group 
    $grouptype = GetGroupType $groupname 
    switch($grouptype){ 
     "o365"{Add-UnifiedGroupLinks -identity "$whatgroupname" -LinkType Members -Links "$whatusername" } 
     "mesg"{Add-DistributionGroupMember -Identity "$whatgroupname" -Member "$whatusername" } 
    } 

을하지만이 문제는 내가 그룹에 역할을 할 수 전에이 그룹의 종류를 알고 있어야한다는 것입니다 :

그래서,이 같은 일을하고 있어요.

내가 갖고있는 그룹의 종류를 어떻게 알 수 있습니까?

답변

1

내가 여기까지 올 수있는 최고입니다. 그러나 그것은 작동합니다 [뒤에서 자기를 가볍게 치십시오].

#figure out what kind of group we have and return: mesg | o365 | distribution 
function GetGroupType([string]$groupname){ 
    #You can use get-group on any group, but the 'grouptype' results are not very descriptive 
    #mesg = "Universal, SecurityEnabled" 
    #o365 = "Universal" 
    #Distribution = "Universal" 
    $thisgrouptype = get-group -identity $groupname -ErrorAction SilentlyContinue | select grouptype 
    if($thisgrouptype.grouptype.contains("Universal")){ 
     if($thisgrouptype.grouptype.contains("SecurityEnabled")){ 
      $grouptype = "mesg" 
     }else{ 
      #since you can't run get-unifiedgroup against a security/distribution group, we should get "Universal" for the return value 
      #so, just check to see whether it is a unified group 
      #$thisgrouptype = get-unifiedgroup -identity $whatgroupname -ErrorAction SilentlyContinue | select grouptype 
      $isUnified = [bool](get-unifiedgroup -identity $groupname -ErrorAction SilentlyContinue) 
      if($isUnified){ 
       $grouptype = "o365" 
      }else{ 
       $grouptype = "distribution" 
      } 
     } 
    }else{ #if it doesn't have "Universal" then it's not what we are looking for 
     $grouptype = "" 
    } 

    return $grouptype 
} 
관련 문제