none
get-aduser and employeenumber -gt 1000000 RRS feed

  • Question

  • My script does not respect $_.employeenumber -gt "1000000 - one can see Jennifer Glove employeenumber is lower than search. What is wrong with the script?

    get-aduser -Filter * -Properties employeenumber | ?{$_.employeenumber -gt "1000000"} | select name, employeenumber

    Samuel Abegunde      1010189      
    Jennifer Glove      110449       
    Melvin Cappe         1010184      


    Thursday, March 1, 2018 1:53 PM

Answers

  • The employeeNumber attribute is a string, not an integer or number. Some employee numbers could include characters. So the -gt comparison is done lexicographically with strings, comparing each character from left to right. The string "101" is greater than "1000000" because "1" (the third character in the string) is greater than "0". You would need to convert the string into an integer to compare numerically.

    Edit: Something like this should work (not tested):

    Get-ADUser -Filter * -Properties EmployeeNumber | ?{[Long]$_.EmployeeNumber -gt 1000000} | select Name, EmployeeNumber

    It would be more efficient to filter before the pipe symbol, to reduce the size of the recordset retrieved from the DC, but that cannot be done in this case.


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)


    Thursday, March 1, 2018 2:53 PM
    Moderator