October 30, 2013

PowerShell - User membership

How to remove particular user (mailbox) from all associated groups (distribution lists)?

import-module ActiveDirectory
$USERNAME = read-host "Enter Username (samaccountname):"
$USERS = (Get-ADUser $USERNAME -properties memberof).memberof
$USERS | Remove-ADGroupMember -Members $USERNAME -Confirm:$false

No comments:

Post a Comment