Cacophony777
asked on
Remove-QADGroupMember Giving Invalid URI Error On Only Some Groups
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:
Any Ideas?
Thanks,
-Al
$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.Any Ideas?
Thanks,
-Al
I suspect it has to do with the type of group. If you look at those that have given you a problem, do you see a common thread? Also, do you have a single-domain environment or multi-?
ASKER
Single Domain environment. What's weird is I have compared the group in the example above with a couple groups that I confirmed the script did work on and they all had the same security and all had the Group Scope set to Universal and Group Type as Security.
The line in the error that states "UriFormatException" leads me to believe that something is pulling over nice from the Get-QADMemberOF cmdlet. Only thing is, even if I just run (Remove-QADGroup 'ALL EXCH USERS' -Member mscruz) on the command line I get the same error and that Syntax looks correct to me...
The line in the error that states "UriFormatException" leads me to believe that something is pulling over nice from the Get-QADMemberOF cmdlet. Only thing is, even if I just run (Remove-QADGroup 'ALL EXCH USERS' -Member mscruz) on the command line I get the same error and that Syntax looks correct to me...
I'm assuming your message above should have been "Remove-QADGroupMember" otherwise that is your problem..
Remove-QADGroupMember wants the DN of the group, so maybe try passing that explicitly? In the script you'd use $group.dn
Remove-QADGroupMember wants the DN of the group, so maybe try passing that explicitly? In the script you'd use $group.dn
ASKER
Yea... That was a typo.
Just tried using the DN when running the command and I'm getting the same result:
Just tried using the DN when running the command and I'm getting the same result:
Remove-QADGroupMember : Invalid URI: The hostname could not be parsed.
At line:1 char:22
+ Remove-QADGroupMember <<<< -identity 'CN=ALL EXCH USERS,OU=Distribution Lists,OU=COMHS,dc=*****,dc=***' -Member mscr
uz
+ CategoryInfo : NotSpecified: (:) [Remove-QADGroupMember], UriFormatException
+ FullyQualifiedErrorId : System.UriFormatException,Quest.ActiveRoles.ArsPowerShellSnapIn.Commands.RemoveGroupMemb
erCmdlet2
Any chance that is a dynamically-generated DL? Maybe try echoing out the DN of the group? Something has to be different about that particular group.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Still not sure why I can't get this to work with Quest ActiveRoles, but I do have it working. Thanks to kollenh for the assistance. I still gave you some points for your time. :-)