Complementing the PS Script by choosing either AAD or AD to hold Your Security Group and Memberships.
[code language=”powershell”]
#Azure Active Directory
Import-Module MSOnline
Connect-MsolService
#Find ObjectId of every Security Group
$Groups = Get-MsolGroup | Select ObjectId,DisplayName
$ExchangeGroupObjectId = $Groups | where {$_.DisplayName -eq "Exchange_Users"} | Select ObjectId
#Placeholder for ObjectIds of every member of Security Group Exchange_Users
$ExchangeGroup = Get-MsolGroupMember -GroupObjectId $ExchangeGroupObjectId.ObjectId
[/code]
With these ObjectIds collected, you can easily perform allmost every MSol command for them.
[code language=”powershell”]
#Active Directory
Import-Module ActiveDirectory
#Find all members of your Security Group ‘usr-exchangeonline’
$ExchangeGroup=Get-ADGroupMember -Identity ‘usr-exchangeonline’ -Recursive | %{get-aduser $_.samaccountname} | select-object -ExpandProperty userprincipalname
[/code]
Little easier to collect a largely usable attribute from a local Active Directory Group. Here we collect the UserPrincipalName, which is also a very usefull attribute for executing commands for them.
Leave a Reply
You must be logged in to post a comment.