How can I determine which version of Windows is running on a server using PowerShell?

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


Get-WmiObject -Class Win32_OperatingSystem | ForEach-Object -MemberName Caption

Or golfed

gwmi win32_operatingsystem |% caption

Result

Microsoft Windows 7 Ultimate

I'd use:

gwmi win32_operatingSystem | select caption

No 'parsing' required. ;^)

Sample output:

Microsoft Windows Server 2003 R2 Standard x64 Edition