Powershell to find Server Operating System

I had a task to find the operating system of all the servers that we had in AD for some of the Microsoft License requirements.

Has anyone done this?

+3


source to share


1 answer


I understood that.

Please feel free to use and modify it. If you have any questions, let me know.

This is a simple command. Hope this helps someone. This gives you the type of operating systems that you have. I am filtering only based on Windows Server and the computer accounts that are active. Then sort by name and select a unique OS.

Get-ADComputer -Filter {(OperatingSystem -like "*windows*server*") -and (Enabled -eq "True")} -Properties OperatingSystem | Sort Name | select -Unique OperatingSystem

      

Output:



OperatingSystem
---------------
Windows Server 2012 R2 Standard
Windows Server 2008 R2 Standard
Windows Server 2012 R2 Standard Evaluation
Windows Server 2008 R2 Enterprise

      

The next command is to get all servers and show your Operating System. Again, I am filtering based on Windows OS and active computer accounts. I am sorting my list by operating system:

Get-ADComputer -Filter {(OperatingSystem -like "*windows*server*") -and (Enabled -eq "True")} -Properties OperatingSystem | sort OperatingSystem | ft DNSHostName, OperatingSystem

      

You can also store the above value in a variable and then get the number of servers in each operating system category:

$Servers = Get-ADComputer -Filter {(OperatingSystem -like "*windows*server*") -and (Enabled -eq "True")} -Properties OperatingSystem | Sort Name

$servers | group operatingsystem  

      

+4


source







All Articles