Getting AD Users with Selected First Letters

by Oct 12, 2018

How would you query for all AD users with names that start with a “e”-“g”? You shouldn’t use a client-side filter such as Where-Object. One thing you can do is use the -Filter parameter with logical operators such as -and and -or:

Get-ADUser -filter {(name -lt 'E') -or (name -gt 'G')} |
  Select-Object -ExpandProperty Name

this example requires the free RSAT tools from Microsoft to be installed)

Twitter This Tip! ReTweet this Tip!