Script Repository

Users with non-unique Employee IDs

January 11, 2017

This script generates a CSV report containing user accounts from all domains managed by Adaxes whose Employee IDs stored in the Employee ID attribute are not unique.

To generate the reports upon request, you can create a Custom Command that runs the script. To schedule the reports, you need to create a Scheduled Task configured for the Domain-DNS object type and run it against any of your AD domains.

To add the script to a Custom Command or Scheduled Task, use the Run a program or PowerShell script action.


  • $csvFilePath - specifies the path to the CSV file that will be created by the script.
Edit Remove
$CsvFilePath = "\\SERVER\Share\Reports\NonUniqueEmployeeIDs.csv" # TODO: modify me

# Search users with Employee IDs
$searcher = New-Object "Softerra.Adaxes.Adsi.Search.DirectorySearcher" $NULL, $False
$searcher.SearchParameters.PageSize = 500
$searcher.SearchParameters.SearchScope = "ADS_SCOPE_SUBTREE"
$searcher.SearchParameters.Filter = "(&(sAMAccountType=805306368)(employeeID=*))"
$searcher.SearchParameters.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
$searcher.VirtualRoot = $True

    $searchResult = $searcher.ExecuteSearch()
    # Build a hash table containing Employee IDs and matching usernames
    $employeeIDs = @{}
    foreach ($userID in $searchResult.FetchAll())
        $employeeID = $userID.Properties["employeeID"].Value
        $user = $Context.BindToObject($userID.AdsPath)
        $userName = [Softerra.Adaxes.Utils.ObjectNameHelper]::GetObjectName($user, 'IncludeParentPath')
        if ($employeeIDs.ContainsKey($employeeID))
            $employeeIDs[$employeeID] += "$userName"
        $employeeIDs.Add($employeeID, @("$userName")) | Out-Null

# Build report
$report = @()
foreach ($employeeID in $employeeIDs.Keys)
    $userNames = $employeeIDs[$employeeID]
    # Skip users with unique Employee IDs
    if ($userNames.Length -eq 1)
    # Add the non-unique Employee ID to the report
    $reportRecord = New-Object PSObject
    $reportRecord | Add-Member NoteProperty EmployeeID $employeeID
    # Add matching usernames to the report
    $reportRecord | Add-Member NoteProperty UserNames $NULL
    foreach ($userName in $userNames)
        $reportRecord.UserNames += "$userName;"
    $report += $reportRecord

# Export to CSV
$report | Export-Csv $CsvFilePath -NoTypeInformation

Comments ( 0 )
No results found.
Leave a comment