Skip to content

Wrong Platform in $PSVersionTable for macOS High Sierra #6513

Closed
MicrosoftDocs/PowerShell-Docs
#2227

Description

$PSVersionTable is returning an incorrect platform for macOS High Sierra 10.13.3.

Source: Engine Update Release Notes for PowerShell Core 6.0.

Steps to reproduce

> $PSVersionTable.Platform

Expected behavior

MacOSX

Actual behavior

Unix

Environment data

> $PSVersionTable

Name                           Value                                                                                                                                                     
----                           -----                                                                                                                                                     
PSVersion                      6.0.2                                                                                                                                                     
PSEdition                      Core                                                                                                                                                      
GitCommitId                    v6.0.2                                                                                                                                                    
OS                             Darwin 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64                                             
Platform                       Unix                                                                                                                                                      
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                   
PSRemotingProtocolVersion      2.3                                                                                                                                                       
SerializationVersion           1.1.0.1                                                                                                                                                   
WSManStackVersion              3.0              

> $IsMacOS

True                                                                                           
$ system_profiler SPSoftwareDataType | grep "System Version"
      System Version: macOS 10.13.3 (17D102)

Activity

  1. mklement0 commented on Mar 27, 2018

    @mklement0
    Contributor

    Unfortunately, the release notes are incorrect.

    What is correct is that PowerShell takes the information from [System.Environment]::OSVersion.Platform, i.e., from CoreFX and there,
    perhaps confusingly, the behavior is by design (from dotnet/platform-compat#29, emphasis added):

    My main concern is with PlatformID.MacOSX. Back in the Silverlight days, Environment.OSVersion.Platform returned PlatformID.MacOSX on OSX. However, on .NET Core it returns PlatformID.Unix on macOS to match Mono's behavior.

    Code that compares Environment.OSVersion.Platform to PlatformID.MacOSX should use the newer RuntimeInformation.IsOSPlatform(OSPlatform.OSX) API instead.

    More backstory at https://github.com/dotnet/corefx/issues/19694


    The unfortunate thing is that the [System.PlatformID] enum that [System.Environment]::OSVersion.Platform return values are instances of still contains MacOSX as a value, but only for historical reasons.

    The upshot is:

    • [System.Environment]::OSVersion.Platform is only useful to contrast platforms with Unix heritage in the abstract with Windows - i.e., to distinguish Linux and macOS on the one hand from Windows on the other.

      • Perhaps we should therefore also introduce an automatic $IsUnix variable to reflect this distinction.
    • $IsMacOs is therefore the best way to determine if you're running on macOS.

    • $PSVersionTable.OS - which contains the value of [System.Runtime.InteropServices.RuntimeInformation]::OSDescription- also reflects the specific platform, but only in a semi-structured way that furthermore refers to macOS as Darwin, the open-source OS on which macOS is based.

  2. added
    Area-Maintainers-Documentation
    Resolution-Answered
    on Mar 27, 2018
  3. SteveL-MSFT commented on Mar 27, 2018

    @SteveL-MSFT
    Member

    Thanks for noticing this. I submitted a fix: MicrosoftDocs/PowerShell-Docs#2227

    Note that you can always click the Edit link on the doc page which will take you to GitHub and submit a fix yourself. Thanks!

  4. mklement0 commented on Mar 27, 2018

    @mklement0
    Contributor

    Steve Lee (@SteveL-MSFT):

    Thanks - hadn't even realized that it was a living document.

    I think it's also important to document the behavior in about_Automatic_Variables, so I've created MicrosoftDocs/PowerShell-Docs#2229

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Maintainers-DocumentationResolution-Answered

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions