system.environment OSVersion property

I was using the Get-LatestWMF5 function in the ISE on a Windows 2012 R2 (PowerShell version 4.0 by default) and it downloaded the wrong file 😦

I was using the [system.environment] .Net class to get the version of the Operating System.
It works fine in the console but not in the ISE.

As you can see, it’s reported as 6.2 which means Windows 8/2012 although I’m on Windows 2012 R2.
ISE.v4

There’s actually a change introduced the API that controls this behavior.
It’s documented on this page: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724451%28v=vs.85%29.aspx
VersionExAPI
Windows PowerShell MVP Dave Wyatt provided this link. Thx Dave 🙂

I propose to replace the code that uses the

[environment]::OSVersion.Version

prev.code.getlatestWMF5
by this:

[Version]$((Get-CimInstance Win32_OperatingSystem).Version)

1 thought on “system.environment OSVersion property

  1. Pingback: Dew Drop – May 27, 2015 (#2022) | Morning Dew

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.