Hello,
1. Here you are. The Distinguished Names (DNs) of the OUs where the script will search for enabled users without managers are specified by $ouDNs. Modify it to your requirements.
The instructions to launch the script remain the same.
Param($csvFilePath)
$ouDNs = @("OU=Users,OU=LA,DC=abc,DC=com","OU=Users,OU=DC,DC=abc,DC=com","OU=Users,OU=NY,DC=abc,DC=com") # TODO: modify me
[Reflection.Assembly]::LoadWithPartialName("Softerra.Adaxes.Adsi")
$admNS = New-Object "Softerra.Adaxes.Adsi.AdmNamespace"
$admService = $admNS.GetServiceDirectly("localhost")
$usersWoManagers = @()
foreach ($ouDN in $OUDNs)
{
$userSearcher = $admService.OpenObject("Adaxes://$ouDN", $NULL, $NULL, 0)
# Search all enabled users without managers
$userSearcher.PageSize = 500
$userSearcher.SearchScope = "ADS_SCOPE_SUBTREE"
$userSearcher.SearchFilter = "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=2)(!manager=*))"
$userSearcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
$userSearcher.VirtualRoot = $False
$searchResultIterator = $userSearcher.ExecuteSearch()
foreach ($user in $searchResultIterator.FetchAll())
{
$userRecord = New-Object PSObject
$userRecord | Add-Member NoteProperty FullName $user.Properties["cn"].Value
$userRecord | Add-Member NoteProperty Username $user.Properties["saMAccountName"].Value
$userDN = New-Object "Softerra.Adaxes.Ldap.DN" $user.Properties["distinguishedName"].Value
$parentDN = $userDN.Parent
$userRecord | Add-Member NoteProperty ParentDN $parentDN.ToString()
$usersWoManagers += $userRecord
}
$searchResultIterator.Dispose()
}
$usersWoManagers | Export-Csv $csvFilePath -NoTypeInformation
-
I'd like to run a script that will check the address to see if it points to A or B.(I'd like this in report form so I can know how many records we have).
It's not quite clear what the report must include. Should it be only the users whose Office / Street Address mismatch or what?
create a scheduled task that will check to see if the street address contains 123 and Modify the user: set office to Office: New York - A
We believe it should be something like this: