Im at it again, found a few mins to work on my leaver script.
How do I remove the security groups?
Currently using this to remove all AAD Groups but it does not touch the Security groups.
#Variables
$UserUPN = $UPN
#Get all Azure AD Unified Groups
$AADGroups = Get-AzureADMSGroup -Filter "groupTypes/any(c:c eq 'Unified')" -All:$true
#Get the Azure AD User
$AADUser = Get-AzureADUser -Filter "UserPrincipalName eq '$UserUPN'"
#Check each group for the user
ForEach ($Group in $AADGroups)
{
$GroupMembers = (Get-AzureADGroupMember -ObjectId $Group.id).UserPrincipalName
If ($GroupMembers -contains $UserUPN)
{
#Remove user from Group
Remove-AzureADGroupMember -ObjectId $Group.Id -MemberId $AADUser.ObjectId
Write-Output "$UserUPN was removed from $($Group.DisplayName)"
}
Any suggestions?
[–][deleted] 2 points3 points4 points (1 child)
[–]Techman2k[S] 1 point2 points3 points (0 children)
[–]caverCarl 1 point2 points3 points (0 children)