We are having some trouble with the following script.
$usersCSVFilePath = "\\\Server\share\exportedAdaxesUsers.csv" # TODO: modify me
#$computerCSVFilePath = "\\Server\share\computers.csv" # TODO: modify me
function BuildReport($filter, $properties)
{
# Search objects in all domains
$searcher = $Context.BindToObject("Adaxes://rootDSE")
$searcher.SearchFilter = $filter
$searcher.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.PageSize = 500
$searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
$searcher.SetPropertiesToLoad($properties)
$searcher.VirtualRoot = $True
try
{
$searchResultIterator = $searcher.ExecuteSearch()
$searchResults = $searchResultIterator.FetchAll()
foreach ($searchResult in $searchResults)
{
# Add object to report
$record = New-Object PSObject
foreach ($propertyName in $properties)
{
$record | Add-Member -MemberType NoteProperty -Name $propertyName -Value $searchResult.Properties[$propertyName].Value
}
$record
}
}
finally
{
$searchResultIterator.Dispose()
}
}
# Create CSV file for users
$userReport = BuildReport "sAMAccountName", "employeeType", "Title", "employeeID", "manager", "departmentNumber"
$userReport | Export-Csv -NoTypeInformation -Path $usersCSVFilePath
# Create CSV file for computers
#$computerReport = BuildReport "(&(objectCategory=computer)(!(userAccountControl:1.2.840.113556.1.4.803:=8192)))" @("managedBy", "distinguishedName")
#$computerReport | Export-Csv -NoTypeInformation -Path $computerCSVFilePath
We are receiving errors stating the following:
We want to export the following attributes and run a comparison against a different excel file, samAccountName, employeeType, JobCode, Manager, title, employeeID and departmentNumber.