Skip to content

pwsh.exe -C ./myscript.ps1 fails from WSL #13106

Closed

Description

Steps to reproduce

In WSL I created the following script file

 echo "Write-Host Hello!" > test.ps1

From WSL I attempted to run the script:

$ pwsh.exe -C ./test.ps1
./test.ps1: AuthorizationManager check failed.
$ pwsh.exe -F ./test.ps1
SecurityError: AuthorizationManager check failed.

Running the same script with Windows PowerShell succeeds:

$ powershell.exe -C ./test.ps1
Hello!

Expected behavior

I expected the script to run successfully, as it does with Windows PowerShell

Actual behavior

$ pwsh.exe -C ./test.ps1
./test.ps1: AuthorizationManager check failed.
$ pwsh.exe -F ./test.ps1
SecurityError: AuthorizationManager check failed.

Environment data

$PSVersionTable


powershell.exe:

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


pwsh.exe:

Name                           Value
----                           -----
PSVersion                      7.0.2
PSEdition                      Core
GitCommitId                    7.0.2
OS                             Microsoft Windows 10.0.19042
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Get-ExecutionPolicy -List


powershell.exe:

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    RemoteSigned

pwsh.exe

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine    RemoteSigned

Activity

  1. added
    Issue-Question
    on Jul 5, 2020
  2. vexx32 commented on Jul 5, 2020

    @vexx32
    Collaborator

    Can you please grab the Get-Error output from the pwsh session that exhibited the error as well? Thanks!

  3. stuartleeks commented on Jul 5, 2020

    @stuartleeks
    Author

    Here you go:

    $ pwsh.exe
    PowerShell 7.0.2
    Copyright (c) Microsoft Corporation. All rights reserved.
    
    https://aka.ms/powershell
    Type 'help' to get help.
    
    Loading personal and system profiles took 1372ms.
    \\wsl$\Ubuntu-20.04\home\stuart> .\test.ps1
    .\test.ps1: AuthorizationManager check failed.
    \\wsl$\Ubuntu-20.04\home\stuart> Get-Error
    
    Exception             :
        Type           : System.Management.Automation.PSSecurityException
        ErrorRecord    :
            Exception             :
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : AuthorizationManager check failed.
                HResult : -2146233087
            CategoryInfo          : SecurityError: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : UnauthorizedAccess
            ErrorDetails          : AuthorizationManager check failed.
            InvocationInfo        :
                ScriptLineNumber : 1
                OffsetInLine     : 1
                HistoryId        : 1
                Line             : .\test.ps1
                PositionMessage  : At line:1 char:1
                                   + .\test.ps1
                                   + ~~~~~~~~~~
                InvocationName   : .\test.ps1
                CommandOrigin    : Internal
            ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
        Message        : AuthorizationManager check failed.
        TargetSite     :
            Name          : ShouldRunInternal
            DeclaringType : System.Management.Automation.AuthorizationManager
            MemberType    : Method
            Module        : System.Management.Automation.dll
        StackTrace     :
       at System.Management.Automation.AuthorizationManager.ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin, PSHost host)
       at System.Management.Automation.CommandDiscovery.ShouldRun(ExecutionContext context, PSHost host, CommandInfo commandInfo,
    CommandOrigin commandOrigin)
       at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(CommandInfo commandInfo, CommandOrigin commandOrigin,
    Nullable`1 useLocalScope, SessionStateInternal sessionState)
       at System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName, CommandOrigin commandOrigin, Nullable`1
    useLocalScope)
       at System.Management.Automation.ExecutionContext.CreateCommand(String command, Boolean dotSource)
       at System.Management.Automation.PipelineOps.AddCommand(PipelineProcessor pipe, CommandParameterInternal[] commandElements,
    CommandBaseAst commandBaseAst, CommandRedirection[] redirections, ExecutionContext context)
       at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][]
    pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
       at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
       at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
        Data           : System.Collections.ListDictionaryInternal
        InnerException :
            Type       : System.UriFormatException
            TargetSite :
                Name          : CreateThis
                DeclaringType : uri
                MemberType    : Method
                Module        : System.Private.Uri.dll
            StackTrace :
       at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
       at System.Uri..ctor(String uriString)
       at System.Management.Automation.ClrFacade.MapSecurityZone(String filePath)
       at Microsoft.PowerShell.PSAuthorizationManager.IsLocalFile(String filename)
       at Microsoft.PowerShell.PSAuthorizationManager.CheckPolicy(ExternalScriptInfo script, PSHost host, Exception& reason)
       at Microsoft.PowerShell.PSAuthorizationManager.ShouldRun(CommandInfo commandInfo, CommandOrigin origin, PSHost host, Exception& reason)
       at System.Management.Automation.AuthorizationManager.ShouldRunInternal(CommandInfo commandInfo, CommandOrigin origin, PSHost host)
            Message    : Invalid URI: The hostname could not be parsed.
            Source     : System.Private.Uri
            HResult    : -2146233033
        Source         : System.Management.Automation
        HResult        : -2146233087
    CategoryInfo          : SecurityError: (:) [], PSSecurityException
    FullyQualifiedErrorId : UnauthorizedAccess
    ErrorDetails          : AuthorizationManager check failed.
    InvocationInfo        :
        ScriptLineNumber : 1
        OffsetInLine     : 1
        HistoryId        : 1
        Line             : .\test.ps1
        PositionMessage  : At line:1 char:1
                           + .\test.ps1
                           + ~~~~~~~~~~
        InvocationName   : .\test.ps1
        CommandOrigin    : Internal
    ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    
    \\wsl$\Ubuntu-20.04\home\stuart>
    
  4. iSazonov commented on Jul 6, 2020

    @iSazonov
    Collaborator

    I guess you run EXE not from WSL - from Windows but cwd is \\wls$\path.

    Related #10674

  5. stuartleeks commented on Jul 7, 2020

    @stuartleeks
    Author

    Yes, I'm running pwsh.exe to load PowerShell in Windows in this particular case, and the path is \\wsl$\Ubuntu-20.04\home\stuart

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

    Issue-QuestionResolution-FixedWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions