Fix [System.Environment]::OSVersion for PowerShell Studio on Windows 10

Post feature requests, product enhancement ideas, and other product-specific suggestions here. Do not post bug reports.
Forum rules
Do not post any licensing information in this forum.
This topic is 6 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
remkow
Posts: 18
Last visit: Tue Jan 11, 2022 4:26 am

Fix [System.Environment]::OSVersion for PowerShell Studio on Windows 10

Post by remkow »

When I run the following code from PowerShell Studio 2017

[System.Environment]::OSVersion
This is the output:

>> Platform: V5 64Bit (STA)

Platform ServicePack Version VersionString
-------- ----------- ------- -------------
Win32NT 6.3.9600.0 Microsoft Windows NT 6.3.9600.0
Both PowerShell.exe and PowerShell ISE on Windows 10 output the correct version information:

[System.Environment]::OSVersion

Platform ServicePack Version VersionString
-------- ----------- ------- -------------
Win32NT 10.0.15063.0 Microsoft Windows NT 10.0.15063.0
Can this be fixed? Perhaps relevant: https://www.remkoweijnen.nl/blog/2017/0 ... owershell/
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Fix [System.Environment]::OSVersion for PowerShell Studio on Windows 10

Post by DevinL »

Which version of PowerShell Studio would you happen to be running?

This was brought to our attention previously and has since been fixed: viewtopic.php?f=12&t=11300
DevinL
SAPIEN Technologies, Inc.
User avatar
remkow
Posts: 18
Last visit: Tue Jan 11, 2022 4:26 am

Re: Fix [System.Environment]::OSVersion for PowerShell Studio on Windows 10

Post by remkow »

2017 build 5.4.136, let me check after updating
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 20
Been upvoted: 37 times

Re: Fix [System.Environment]::OSVersion for PowerShell Studio on Windows 10

Post by Alexander Riedel »

The API you use to determine the Windows version is deprecated: https://msdn.microsoft.com/en-us/librar ... .110).aspx

"Starting with Windows 8, the OSVersion property returns the same major and minor version numbers for all Windows platforms. Therefore, we do not recommend that you retrieve the value of this property to determine the operating system version."

Here are a few other ways of doing this:
http://stackoverflow.com/questions/7330 ... ne/7330368
Or use the method in the blog article you provided.

While we tagged the executable in question now as a Windows 10 executable, it is not a reliable way to determine the OS version.
The API you use will ALWAYS only report the largest version a product is tagged for, not the true OS version.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
remkow
Posts: 18
Last visit: Tue Jan 11, 2022 4:26 am

Re: Fix [System.Environment]::OSVersion for PowerShell Studio on Windows 10

Post by remkow »

Fixed indeed:
Platform ServicePack Version VersionString
-------- ----------- ------- -------------
Win32NT 10.0.15063.0 Microsoft Windows NT 10.0.15063.0
This topic is 6 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked