Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Created January 17, 2014 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/8477243 to your computer and use it in GitHub Desktop.
Save michaellwest/8477243 to your computer and use it in GitHub Desktop.
Find users with duplicate employee ids.
# Get all the enabled users.
$users = Get-ADUser -Filter { Enabled -eq $true } -Properties EmployeeId
# Collect all the ids and format them to 7 characters.
$ids = @{}; $users | ForEach-Object { if($_.EmployeeId) { $ids[("{0:D7}" -f [int]$_.EmployeeId)] += 1 } }
$filteredUsers = $users | Where-Object { if($_.EmployeeId) { $ids[("{0:D7}" -f [int]$_.EmployeeId)] -gt 1 } }
$filteredUsers | Select-Object -Property SamAccountName, EmployeeId
$filteredUsers | Export-Csv -Path "C:\temp\DuplicateEmployeeId-$((Get-Date).ToString('yyyyMMddThhmmss')).csv" -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment