Home > Mobile >  retrieving specific userlogonid from AD
retrieving specific userlogonid from AD

Time:11-19

I am trying to retrieve all users from AD using PowerShell that have the same SAMaccountname as their employeeid but i am having difficulty trying to get that information. Would anyone be able to assist how i can go about it?

I have tried the below

Get-ADUser -Filter * | Select GivenName, SAMAccountName and also Get-ADUser -Filter "employeeID -eq '$($employee.employeeID)'" -Properties SamaccountName | Export-Csv -Path C:\Support\GDPid.csv -NoTypeInformation

but this will give me all the users in AD. How do i go about retrieving specific users with SAMaccountname same as their employeeid

Thank you

CodePudding user response:

You have to pull back everything you want to compare, then perform that comparison on the client side, as LDAP doesn't provide a way to compare attributes with one another on the server side*.

Get-ADUser -Filter * -Properties EmployeeId, GivenName | 
    Where-Object { $_.EmployeeId -eq $_.SAMAccountName } |
    Select-Object SAMAccountName, EmployeeId, GivenName |
    Export-Csv -Path 'C:\Support\GDPid.csv' -NoTypeInformation
  • Related