Ying Li at myITforum.com

PowerShell & System Center

PowerShell script to list user group membership in Active Directory

Here is a powershell script to list target user’s group membership in Active Dreictory

$root=([adsi]"").distinguishedName
$ou=[adsi]("LDAP://ou=x,ou=y,ou=z,"+$root)

# here targetCN should be the exact CN for interested user in your AD
$user=$ou.psbase.children.find("cn=tartetCN ")
$groups = $user.memberof
foreach($group in $groups)
{
$strGroup = $group.split(',')[0]
$strGroup = $strGroup.split('=')[1]
$strGroup
}

Posted: Aug 27 2007, 02:28 PM by yli628 | with no comments
Filed under:

Comments

No Comments