Monday, April 14, 2008

Read groupmembers from AD

A friend of mine asked how he could read from his local AD, in order to create a script for verifying group membership against a saved list. Here is a small piece of code that helped him:

$users = [adsi]"LDAP://cn=groupName,ou=ouName,dc=MyDomain,dc=MyDomain2"

foreach ($user in $users.Member) {
    Write-Host (([adsi]"LDAP://$user").displayname)
}

No comments: