function Get-Users {
$Users = @()
$objDomain = New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = ("(&(objectClass=user)(objectCategory=person))")
$intProperties = $objSearcher.PropertiesToLoad.Add("name")
$intProperties = $objSearcher.PropertiesToLoad.Add("createTimeStamp")
$objResults = $objSearcher.FindAll()
ForEach ($objResult in $objResults) {
$Users += $objResult.Properties | `
Select-Object @{n="name";e={$_.name}},@{n="createTimeStamp";e={$_.createtimestamp}}
}
return $Users
}
# Example exporting results to a CSV file
Get-Users | Export-CSV -Path "C:\Stuff\test.csv"
|