If you want to know the computer objects in a particular OU or group, you can work with the GUI tools Active Directory Users and Computers (ADUC) or Active Directory Administrative Center. However, PowerShell and dsquery are faster and more flexible.

Wolfgang Sommergut

Wolfgang Sommergut has over 20 years of experience in IT journalism. He has also worked as a system administrator and as a tech consultant. Today he runs the German publication WindowsPro.de.

Say you want to find out which computers will be affected if you link a GPO to a certain OU. You could run the following dsquery command:

The result would be a list of computer names. If you omit the -o switch with the rdn value, you receive a list of Distinguished Names.

If you need further properties in addition to the name, or if you want to add a filter to the query, the Get-ADcomputer cmdlet is helpful. Like its counterpart Get-ADUser (which allows you to read user objects), you have to pass either the object name or a filter as parameter. If you want to display all computers, you can use -Filter with a wildcard:

As usual, you can add conditional statements to the filter to restrict the output. The following example would display all Windows 8.1 PCs provided you named the computers accordingly:

To limit the query to a particular OU, you need the additional parameter -SearchBase:

The search in a particular group follows a similar pattern:

If you want to list not only the default computer object attributes, you have to add -Properties * to the command.

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!

8+
Share
4 Comments
  1. David 3 years ago

    How can I use this Cmdlet to show all windows 10 computers that have not been upgraded to Windows 10 Anniversary update?

    Thanks.

    2+

    • Ben Buck 2 years ago

      Here is one way to do it

      Part A
      $workstations=get-adcomputer -filter * -searchbase "ou=workstations, dc=contoso, dc=com" | select-object -expand name
      For contoso and com, use your own companie's domain.  for example dc=Microsoft dc=local

      Part B
      get-wmiobject win32_operatingsystem -cn $workstations | export-csv .\windows10.csv

      In part A you store the computer names as a variable called $workstations.  get-adcomputers produces names in format .adcomputers.  In part B -computer names must be read in as strings, not .adcomptuers.  Do more research on this, it is a very important topic.  The command -expand name converts it from .adcomputers to string.

      In part b you use the variable to pass all the computer names, and save out the file as .csv

      Note that this command takes some time to run.  Also, any computers not turned on will result in red error text.  Do not kill or control + C on the powershell prompt.  Allow it to finish and get back to the flashing prompt.

      In the final report, convert over to Excel and delete all columns but description and build number.  As of May 2017 the current Creators Edition build is 15063.

      There are some ways to clean up this command.  You can eliminate the variable and combine both commands into one using parenthesis.  Its also possible to select only name and description in part b so that you don't have to delete extra data in the csv file.  Experiment!

       

      1+

    • Randy 2 years ago

      This will do the trick:

      (Get-ADComputer -properties * -filter "OperatingSystem  -like 'Windows 10*' -and OperatingSystemVersion -notlike '*14393*'").name

      The ".name" at the end will just return the computer name. You can get rid of that if you want all of the information.

      "OperatingSystem  -like 'Windows 10*'" will return Windows 10 only, and "OperatingSystemVersion -notlike '*14393*'" will filter out anything not on the Anniversary edition. Unfortunately, this will also exclude anything newer than that. So if you want to make sure that they're all up-to-date, just replace 14393 with the current version number.

      The "searchBase" switch is optional, and is only really necessary if you only want to search through a part of your domain. Without that switch, it will default to searching the entire domain. Because of this, I left it out of my example.

      1+

  2. Guru 9 months ago

    How can I get computer names of particular OU along with properties of operating system, version and Service Pack.

    3+

Leave a reply

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

*

© 4sysops 2006 - 2019

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account