Well it's challenging to write scripts because of not a main stream scripter but it's fun
So here is the latest script to find users in specific ou and retrieve their specific properties.
$strFilter ="(&(objectclass=user)(objectCategory=person))"
$objOU = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=Privileged Accounts,OU=User Accounts,DC=govinda,DC=com")
$objSearcher = New-object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objOU
$objSearcher.PageSize = 1000
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"
$objSearcher.PropertiesToLoad.Addrange(@("sAMAccountName","employeeid","name"))
$colResults=$objSearcher.FindAll()
# Data Format in List
foreach($objResult in $colResults)
{ $objItem = $ObjResult.Properties;
"Name: " + $objItem.name;
"sAMAccountName: " + $objItem.samaccountname;
"employeeID: " + $objItem.employeeid;
write-host ************************
}
# Data Format in Table
$colResults | FT @{label="Name";Expression={$_.Properties.name}},@{label="sAMAccountName";Expression={$_.Properties.samaccountname}},@{label="EmployeeID";Expression={$_.Properties.employeeid}}
No comments:
Post a Comment