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)
Advertisements

One thought on “system.environment OSVersion property

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s