ADComputer Powershell Cmd’s

Have you ever had to produce a report on what service pack your computer/servers have installed? Or, the location of the computer’s OU?  Or a list of your servers IP’s?  Below are sample powershell cmd using ADComputer.

Let’s start with the basic: To get powershell examples, help type:

Get-help Get-ADComputer -examples

Now let’s look at a computers properties:

Get-ADComputer <ComputerName> -Properties *

This will produce all the active directory attributes relate to the computers on the left and the information of those attributes on the right (image below).  This information will be used to fill in the -properties information for the powershell cmds listed below.

Below is one of the Get-help examples provide to us:

Get-ADComputer -Filter ‘Name -like “Fabrikam*”‘ -Properties IPv4Address | FT Name,DNSHostName,IPv4Address -A

The command listed above will return the computers Name, DNShostname, and IP address.  Let’s change this command to show us the computer’s name, operating system, and service pack.

Get-ADComputer -Filter * -Properties Name, Operatingsystem, OperatingSystemServicePack | FT Name, OperatingSystem, OperatingSystemServicePack

Now let’s filter the command to show us only servers.  The command listed below will search for the word “server” in the operating system column and then display that information:

Get-ADComputer -Filter ‘Operatingsystem -like “*server*”‘ -Properties Name, Operatingsystem, OperatingsystemServicePack | FT Name, OperatingSystem, OperatingSystemServicePack

Let’s sort the information listed above by operating system and then by name:

Get-ADComputer -Filter ‘Operatingsystem -like “*server*”‘ -Properties Name, Operatingsystem, OperatingsystemServicePack | Sort-Object OperatingSystem, Name | FT Name, OperatingSystem, OperatingSystemServicePack -AutoSize

If you notice we made minor changes to customize the powershell cmd to provides us with the information we needed.


Leave a comment