Getting the Windows OS Version on specific OU is very useful for System Administrator. For example for the upgrade plan or system architecture plan.
Before we continue, you have to import the
Import-Module activedirectory
For your information, In PowerShell 3.0 and above, this module is imported by default if RSAT Tools for Active Directory. You can install it using the following command:
Install-WindowsFeature -Name RSAT-ADDS
Get-ADComputer
Get-ADComputer is a cmdlet to gets a computer or perform a search to retrieve multiple computers. Get-ADComputer returns set of ADComputer property values. You can get a list of all the properties of an ADComputer object by running the following command:
Get-ADComputer <computer> -Properties * | Get-Member
Get the Computer information on the sepecific OU
To display the information about the computer objects in a particular OU, use the SearchBase parameter:
Get-ADComputer -SearchBase 'OU=US,DC=msnoob,DC=com' -Filter * -Properties * | FT Name, OperatingSystem, OperatingSystemServicePack, OperatingSystemVersion -Wrap -Auto
You can Also use Server filtering. For example, you want to get all the server with Windows Server OS Installed.
Get-ADComputer -SearchBase 'OU=US,DC=msnoob,DC=com' -Filter {OperatingSystem -Like "Windows *Server*"} -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack -Wrap -Auto
Export to CSV
You can also export the search result from Get-ADComputer above by using Export-CSV command. Below is the example of the command:
Get-ADComputer -SearchBase 'OU=US,DC=msnoob,DC=com' -Filter * -Properties * | FT Name, OperatingSystem, OperatingSystemServicePack, OperatingSystemVersion -Wrap -Auto | Export-CSV GetWindowsVersion.csv -NoTypeInformation -Encoding UTF8
We hope this article can help you to Get Computer information using PowerShell command. If you liked this article, then please share with the others. You can also find us on Twitter and Facebook.