Get list of machines by OS type from Active Directory

The old method of doing this is below. Here’s how you can get the same result using Powershell:

Get-ADComputer -Filter {OperatingSystem -like "*Server*"} -Properties OperatingSystem

Refining the output a little bit:

Get-ADComputer -Filter {OperatingSystem -like "*Server*"} -Properties OperatingSystem | Select Name,OperatingSystem | Sort Name,OperatingSystem

Grouping results up by OperatingSystem (Gives you a nice list of the how many of each operating system type you have in AD):

Get-ADComputer -Filter {OperatingSystem -like "*Server*"} -Properties OperatingSystem | Group-Object OperatingSystem | Sort OperatingSystem

Here is an easy way of getting a list of computers that have a particular OS type from Active Directory using DSQuery.

dsquery * domainroot -filter "(&(objectCategory=computer)(operatingSystem=Windows XP*))"

The command above would give you a list of all computers that have a Windows XP operating system. For Windows Servers, change the command as follows:

dsquery * domainroot -filter "(&(objectCategory=computer)(operatingSystem=Windows Server*))"

The output of the commands above would look something like this:

dsget succeeded

Note the ‘samid’ at the head and ‘dsget succeeded’ at the end and the ‘$’ at the end tail of every server name. If you are like me, and you would like just get a nice clean output with only server names, you can run this command:

for /f "Tokens=1 delims=$" %a in ('dsquery * domainroot -filter "(&(objectCategory=computer)(operatingSystem=Windows Server*))"^| dsget computer -samid^|find /V "samid" ^| find /V "dsget"') do echo %a

The output of the command shown above would be:


… and can be used as input to a file or another command etc…


Great siva! I’ve been looking for a command like this the whole morning. I wanted to get a list of all my servers and their operating systems and the commands dsquery ou, computer didin’t solve it. Now I have the list 😀

Try this instead if you just need only server name and OS ( all server OS)

dsquery * domainroot -filter “(&(objectCategory=computer)(operatingSystem=*Server*))” -attr name Operatingsystem

Leave a Reply

Your email address will not be published. Required fields are marked *