Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 eggheadcafe.com/software/aspnet/31845351/… –  ta.speot.is 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
    
google.com.au/… –  ta.speot.is Jul 14 '11 at 11:03
add comment

3 Answers

up vote 5 down vote accepted

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

share|improve this answer
add comment

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
add comment
(Get-WmiObject Win32_OperatingSystem).Caption

Or golfed

(gwmi win32_operatingsystem).caption

Result

Microsoft Windows 7 Ultimate
share|improve this answer
add comment

Your Answer

 
discard

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.