question

PaulSam-0565 avatar image
0 Votes"
PaulSam-0565 asked PaulSam-0565 commented

Powershell script to remove group owners as group members Azure AD

Hello everyone, I need a Powershell script to get all the group owners as members on Azure AD and remove them (Office 365 groups). Could you please guys Help? Thanks

azure-ad-connectazure-ad-user-provisioning
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

michev avatar image
1 Vote"
michev answered PaulSam-0565 commented

That's not a supported scenario, an Owner must be a member of the corresponding Office 365 Group.

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Where when you create an office 365 group the owner is a member by default. Is there a way to remove it?

0 Votes 0 ·

What I want is to remove them from Azure.

0 Votes 0 ·

This is my script.

What I want is to use "Remove-AzureADGroupOwner" somehow.

$groups=Get-AzureADGroup -All $true
$resultsarray =@()
ForEach ($group in $groups){
$members = Get-AzureADGroupMember -ObjectId $group.ObjectId -All $true
ForEach ($member in $members){
$UserObject = new-object PSObject
$UserObject | add-member -membertype NoteProperty -name "Group Name" -Value $group.DisplayName
$UserObject | add-member -membertype NoteProperty -name "Member Name" -Value $member.DisplayName
$UserObject | add-member -membertype NoteProperty -name "ObjType" -Value $member.ObjectType
$UserObject | add-member -membertype NoteProperty -name "UserType" -Value $member.UserType
$UserObject | add-member -membertype NoteProperty -name "UserPrinicpalName" -Value $member.UserPrincipalName
$resultsarray += $UserObject
}
}
$resultsarray | Export-Csv -Encoding UTF8 -Delimiter ";" -Path "C:\test\output.csv" -NoTypeInformation

0 Votes 0 ·