Skip to content

Instantly share code, notes, and snippets.

@lantrix
Created November 19, 2015 06:57
Show Gist options
  • Select an option

  • Save lantrix/e205a957f505856fccb3 to your computer and use it in GitHub Desktop.

Select an option

Save lantrix/e205a957f505856fccb3 to your computer and use it in GitHub Desktop.
Windows version detection taken from https://chocolatey.org/packages/PowerShell/
$osVersion = (Get-WmiObject Win32_OperatingSystem).Version
$os = (Get-WmiObject "Win32_OperatingSystem")
switch ([version]$osVersion) {
{($_ -ge [version]"6.0") -AND ($_ -le [version]"6.0.6001")} {
Write-Output "OS is Vista or 2008"
}
{($_ -eq [version]"6.1.7600")} {
Write-Output "OS is Win7 or Server 2008 R2 (NON-SP1)"
}
{($_ -ge [version]"6.1.7601") -AND ($_ -lt [version]"6.2")} {
Write-Output "OS is Win7 (SP1 or later) or Server 2008 R2 (SP1 or later)"
}
{($_ -ge [version]"6.2.9200") -AND ($_ -lt [version]"6.3")} {
if($os.ProductType -eq 3) {
Write-Output "OS is Server 2012"
}
else {
Write-Output "OS is Win 8 (not 8.1)"
}
}
{($_ -ge [version]"6.3.9600") -AND ($_ -lt [version]"6.4")} {
Write-Output "OS is Win8.1 Server 2012 R2"
}
{($_ -ge [version]"6.4") -or ($_ -ge [version]"10.0")} {
Write-Output "OS is Windows 10"
}
default {
# Windows XP, Windows 2003, Windows Vista, or unknown?
throw "Unknown older operating system (Windows XP, Windows 2003, Windows Vista, or ?)."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment