This Windows PowerShell script uses WMI to determine the OS Version ex: Windows XP, Windows Vista, etc. You can target a remote computer to reteive its information as well.

PowerShell
Edit|Remove
Param($computer = "localhost")

Function Get-OSVersion($computer,[ref]$osv)
{
 $os = Get-WmiObject -class Win32_OperatingSystem `
       -computerName $computer
 Switch ($os.Version)
  {
    "5.1.2600" { $osv.value = "xp" }
    "5.1.3790" { $osv.value = "2003" }
    "6.0.6001" 
               {
                 If($os.ProductType -eq 1)
                   {
                    $osv.value = "Vista"
                   } #end if
                 Else
                   {
                    $osv.value = "2008"
                   } #end else
               } #end 6001
    "6.1.7600"
                {
                 If($os.ProductType -eq 1)
                   {
                    $osv.value = "Win7"
                   } #end if
                 Else
                   {
                    $osv.value = "2008R2"
                   } #end else
               } #end 7600
     DEFAULT { "Version not listed" }
  } #end switch
} #end Get-OSVersion

# *** entry point to script ***
$osv = $null
Get-OSVersion -computer $computer -osv ([ref]$osv)
$osv