A clunky little function to if the script is running on a computer which has “at least” a particular Windows Version.  So if you wanted to allow the script to run on Windows 8 or newer, you would use (Test-WindowsVersion 8).  The Do/While code is just a loop from 1 to 11 to demonstrate it.

function Test-WindowsVersion {
    [parameter(Mandatory=$True,Position=0)] [int] $MajorVersion
  $wv = Get-CimInstance -Namespace root\cimv2 -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty Version
  [int]$wv = $($wv.ToString()).Split(".")[0]
  if ($wv -ge $MajorVersion) {
    Return $True

$i = 1
do {
  if (Test-WindowsVersion $i) {
    Write-Host "Windows $i or newer"
  else {
    Write-Host "Older than Windows $i"
} while ($i -le 11)

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s