kwizcom banner advertisement

PowerShell Script to List All the Users from LDAP

Wanted to retrieve all the users from a AD LDS based LDAP instance. Code
$Dom = "LDAP://<Server-Name>/CN=Users,CN=LDAP,DC=SharePoint,DC=COM"
$Root = New-Object DirectoryServices.DirectoryEntry $Dom

# Create a selector and start searching from the Root of AD
$selector = New-Object DirectoryServices.DirectorySearcher
$selector.SearchRoot = $root
# Filter the users with -like "CN=Person*". Note the ForEach loop
$adobj= $selector.findall() | where {
$_.properties.objectcategory -like "CN=Person*"
}
foreach ($person in $adobj)
{
$prop=$person.properties
Write-host "First name: $($prop.givenname) Surname: $($prop.sn) User: $($prop.cn)"
}
Write-host "There are $($adobj.count) users in the $($root.name) domain" 

read-host
PowerShell Script to List All the Users from LDAP PowerShell Script to List All the Users from LDAP Reviewed by Salaudeen Rajack on December 06, 2011 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.