In my other question Ich fragte, wie man den Typ des Benutzerkontos bestimmen kann. Aber jetzt muss ich herausfinden, welche Art von Gruppe ich haben könnte.Wie bestimmt man den Gruppentyp?
Ich schreibe eine Funktion, die einen Benutzer zu einer Gruppe hinzufügen wird. Das Problem ist, dass ich wissen muss, welche Art von Gruppe es ist, bevor ich den Benutzer hinzufügen kann. Es kann sich um eine moder o365-Gruppe, eine Sicherheitsgruppe, eine Verteilerliste oder eine E-Mail-aktivierte Sicherheitsgruppe handeln.
Also, ich mache etwas wie folgt aus:
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" }
}
Aber das Problem dabei ist, dass ich weiß, muss, welche Art von Gruppe ist es, bevor ich auf die Gruppe handeln kann.
Wie kann ich herausfinden, welche Art von Gruppe ich habe?