How to Determine Windows Version on a Server Using PowerShell

powershellwindows

I'm trying to write a PowerShell script that I can run on remote servers. In these scripts I want to carry out different functions depending on which version of Windows is running on the machines.

I cant seem to find any useful information on the net about how to determine which version of Windows is running on the machine that the script is being run on (Server 2003, Server 2008 R2 etc). Any ideas how I can do this?

Best Answer

This is the one I would go with:

gwmi win32_operatingSystem | select name

As todda.speot.is mentioned, that is the same link I found, but there are a lot of anwsers within it, and I tested them. That one I gave appears to give you what you want, although you will have to parse it (I think that is the right term).

Here is a sample output:

Microsoft Windows Server 2003 R2 Standard x64 Edition|C:\WINDOWS|\Device\Harddisk0\Partition1

http://www.eggheadcafe.com/software/aspnet/31845351/reliable-way-to-get-windows-version.aspx