I need help in a finding Azure AD Groups where members are null. Someone please help to provide a powershell script this this.
I have few empty groups in Azure AD and i need to find those through powershell script.
CodePudding user response:
I don't think there is a direct way to get this but it can be done using a 2-step approach viz as follows:
1.Get the list of groups using the following : https://docs.microsoft.com/en-us/powershell/module/azuread/get-azureadgroup?view=azureadps-2.0#example-1--get-all-groups
2.Use the result from above and run a loop on the group names with the following command:
(Get-AzADGroup -DisplayName "<DisplayNameofGroup>" | Get-AzADGroupMember).count
OR
with the group GUID as follows:
(Get-AzureADGroupMember -All $true -ObjectId "GUID OF AAD GROUP" | select mail).Count
Then sort and keep those group id's or names which have no members to a list.
CodePudding user response:
Thanks Srinath. Also, i am able to get it with the below command.
Get-AzureADGroup -All $True | ? {(Get-azureadgroupmember -ObjectId $_.ObjectId).count -eq 0 }