PowerShell Script to Find OS of Multiple Computers

PowerShell Script to Find OS of Multiple Computers

How To Get Operating System Details Using PowerShell

Enterprises with thousands of computers can be hard to manage, especially when the computers are running different versions of a operating system. As administrators want to upgrade computer OS's that are phased out, but still operating, it can be difficult spotting which exact computer is running which operating system. 

Microsoft has provided some solutions to this challenge, such as PowerShell and some other scripts that will query each computer and report back what the current operating system is. Here's how you can check the OS versions that all computers in your environment are running. 

Open up a PowerShell cmd window and enter the following command:
Get-ADComputer -Filter * -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion -Wrap –Auto
This command is filtering all computers for all their properties. It then redirects the output into a formatted table. The only attributes that the table contains are the computer name, operating system description, service pack, and OS version. It also automatically sizes and wraps the data.

In order to find all servers in the domain, run the following command:
Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*"} -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack -Wrap -Auto
In order to find all servers running Windows Server 2008, run:
Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*2008*"} -Property * | Format-Table Name,OperatingSystem,OperatingSystemServicePack -Wrap -Auto
In order to find all servers running Windows Server 2008 R2, run:
Get-ADComputer -Filter {OperatingSystem -Like "Windows Server*r2*"} -Property * | Format-Tab
These cmdlets return a CSV that contains a list of all the computers or servers running which version of the operating system.