Get-ADComputer -Filter * -Properties * | ?{$_.OperatingSystem -like "*Server*"}
What’s happening here?
- Get all computers in the domain (filter -*) and all properties (the property we want is not in the filtered properties that you get if you just run Get-ADComputer without -Properties *)
- Send those computers through a Where-Object (?{}) filter block.
- Filter by the attribute OperatingSystem containing the word ‘Server’
You can pipe this again and select some filtered attributes. For instance, if you just want the name and the location in AD then you run it like this:
Get-ADComputer -Filter * -Properties * | ?{$_.OperatingSystem -like "*Server*"} | select Name, DistinguishedName