Tuesday, December 6, 2011

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)
Write-host "First name: $($prop.givenname) Surname: $($prop.sn) User: $($prop.cn)"
Write-host "There are $($adobj.count) users in the $($root.name) domain" 


You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...