Trying to remove user from all groups in an Active Directory using PowerShell script

Viewed 28757

I'm trying to use a PowerShell script to accept input from the user based on what user they want removed from all groups. Is my syntax wrong? Here's what I have so far.

$User1 = Read-Host -Prompt 'Enter the username of the employee you wish to change'

Get-ADUser -Identity $User1 -Properties memberof |
    Select-Object -ExpandProperty memberof |
    Remove-ADGroupMember -Identity CISCOVPN, FS-001

Where CISCOVPN and FS-001 are two of the groups I want $User1 removed from. Is there a way to just say remove from all groups?

2 Answers
Get-ADPrincipalGroupMembership $user| foreach {Remove-ADGroupMember $_ -Members $user - 
Confirm:$false}
Related