Hi I am new to PowerShell, I have a CSV file of Active directory user names, I need to remove them from all their group memberships except the default "Domain Users"
I have this script but it doesn't work, and wondering if any one could advise me on what I am doing wrong.
Import-Module ActiveDirectory
$users = import-csv C:\temp\AD\groups_test.csv
Get-ADPrincipalGroupMembership $user| foreach {Remove-ADGroupMember $_ -Members $user -Identity
Confirm:$false}
Assuming your CSV has a column
SAMAccountNamewith the user's username, do this:PowerShell will automatically bind the
ADGroupobjects output byGet-ADPrincipalGroupMembershiptoRemove-ADGroupMember's-Identityparameter.