Description
List Users from a Organizational Unit (OU).
Source Code
$Dom = "LDAP://OU=OfficeUsers,DC=powershellscripts,DC=blogspot,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"
Source Code and Samples
Thursday, 8 February 2007
Subscribe to:
Post Comments (Atom)
3 comments:
TYPO - should be:
| where
not just
where
Thanks for the script
Thanks for the script - but it only counts the number of "Person" objects in that specific OU.
Post a Comment