PowerShell / PowerShellStandard

MIT License
159 stars 24 forks source link

Cmdlet support between Windows PowerShell and PowerShell Core not equal #99

Open jcasale opened 2 years ago

jcasale commented 2 years ago

Prerequisites

Steps to reproduce

I have a cmdlet that is based on PowerShellStandard.Library v7.0.0-preview.1 that references System.Security.Cryptography.ProtectedData to use data protection API.

In PowerShell Core, calls to any data protection APIs work as expected, but when the cmdlet is loaded in Windows PowerShell 5.1, those calls throw a platform not supported exception.

Is my understanding of the use of this library wrong, and the scenario above is not possible?

Expected behavior

A call inside the cmdlet such as the following works on both versions.

var secret = ProtectedData.Protect(bytes, null, this.Scope);

Actual behavior

The same call in `Expected behavior` throws a `PlatformNotSupportedException` exception instead.

Error details

New-DataProtectionSecret : Windows Data Protection API (DPAPI) is not supported on this platform.
At C:\scm\dotnet\PSDataProtection\debug.ps1:5 char:5
+     New-DataProtectionSecret -Scope LocalMachine -SecureString (Conve ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-DataProtectionSecret], PlatformNotSupportedException
    + FullyQualifiedErrorId : System.PlatformNotSupportedException,PSDataProtection.NewDataProtectionSecret

Environment data

# Working
PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.0-preview.6
PSEdition                      Core
GitCommitId                    7.3.0-preview.6
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

# Failing
PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.22000.653
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22000.653
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version

7.0.0-preview.1

Visuals

No response