I am working on writing a script to automate some of the Active Directory tasks we perform when a user leaves our organization. One of those tasks is removing the user from all groups except "Domain Users." Here is a snippet of that code:
$AllGroups = Get-QADMemberOf $User
Foreach ($Group in $AllGroups)
If ($Group -ne "Domain Users")
$null = Remove-QADGroupMember $Group -Member $User
Write-Host "Removed $User from group: $Group ..."
The problem is that for a select handful of groups this isn't working (it works great for most). I get this error:
Remove-QADGroupMember : Invalid URI: The hostname could not be parsed.
+ Remove-QADGroupMember <<<< 'ALL EXCH USERS' -Member mscruz
+ CategoryInfo : NotSpecified: (:) [Remove-QADGroupMember], UriFormatException
+ FullyQualifiedErrorId : System.UriFormatException,Quest.ActiveRoles.ArsPowerShellSnapIn.Commands.RemoveGroupMemberCmdlet2
I have made sure that I have rights to these groups and have verified that I can make the same change manually in Active Directory.