Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
I Googled for 30 seconds and found… – Jul 14 '11 at 10:49
thanks for that help, i guess i have some things to learn when searhing the net for answers. out of interest, what did you type into google to find that answer? – Vermin Jul 14 '11 at 10:57
@Vermin I tried a few based on these words then I read a number of the results: using powershell determine windows version – KCotreau Jul 14 '11 at 11:00… – Jul 14 '11 at 11:03
up vote 7 down vote accepted

This is the one I would go with:

gwmi win32_operatingSystem | select name

As 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

share|improve this answer
Get-WmiObject -Class Win32_OperatingSystem | ForEach-Object -MemberName Caption

Or golfed

gwmi win32_operatingsystem |% caption


Microsoft Windows 7 Ultimate
share|improve this answer

I'd use:

gwmi win32_operatingSystem | select caption

No 'parsing' required. ;^)

Sample output:

Microsoft Windows Server 2003 R2 Standard x64 Edition

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.