PowerShell: Passing -ErrorAction Stop to an implicitly remoting function is no longer honored when calling from v7.4-preview.5

Prerequisites

Steps to reproduce

Thanks to @mklement0 for providing this very straightforward repro step

Get-AppLockerFileInformation NoSuch.exe -ErrorAction Stop; 'after'

Expected behavior

The “after” should not be printed.

 Get-AppLockerFileInformation NoSuch.exe -ErrorAction Stop; 'after'
Get-AppLockerFileInformation: Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.

Actual behavior

“after” is printed

Get-AppLockerFileInformation NoSuch.exe -ErrorAction Stop; 'after'
Get-AppLockerFileInformation: Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
after

This problem doesn’t happen in PowerShell 7.3.6

Error details


OriginInfo            : localhost
Exception             : 
    Type                           : System.Management.Automation.RemoteException
    SerializedRemoteException      : System.Management.Automation.ItemNotFoundException: Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
                                     at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider provider, CmdletProviderContext context)
                                     at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletProvider& providerInstance)
                                     at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, CmdletProvider& providerInstance)
                                     at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, ProviderInfo& provider, CmdletProvider& providerInstance)
                                     at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, ProviderInfo& provider, CmdletProvider& providerInstance)
                                     at System.Management.Automation.PSCmdlet.GetResolvedProviderPathFromPSPath(String path, ProviderInfo& provider)
                                     at Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.CmdletHelper.ResolvePSPath(PSCmdlet cmdlet, String path)
                                     at Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.CmdletHelper.ResolvePSPaths(PSCmdlet cmdlet, ICollection`1 paths)
    SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
    ErrorRecord                    : 
        Exception             : 
            Type                           : System.Management.Automation.RemoteException
            SerializedRemoteException      : System.Management.Automation.ItemNotFoundException: Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
                                             at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider provider, CmdletProviderContext context)
                                             at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletProvider& providerInstance)
                                             at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, CmdletProvider& providerInstance)
                                             at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, ProviderInfo& provider, CmdletProvider& providerInstance)
                                             at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, ProviderInfo& provider, CmdletProvider& providerInstance)
                                             at System.Management.Automation.PSCmdlet.GetResolvedProviderPathFromPSPath(String path, ProviderInfo& provider)
                                             at Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.CmdletHelper.ResolvePSPath(PSCmdlet cmdlet, String path)
                                             at Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.CmdletHelper.ResolvePSPaths(PSCmdlet cmdlet, ICollection`1 paths)
            SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
            ErrorRecord                    : 
                Exception             : 
                    Type                           : System.Management.Automation.RemoteException
                    SerializedRemoteException      : System.Management.Automation.ItemNotFoundException: Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
                                                     at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider provider, CmdletProviderContext context)
                                                     at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletProvider& providerInstance)
                                                     at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, CmdletProvider& providerInstance)
                                                     at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, ProviderInfo& provider, CmdletProvider& providerInstance)
                                                     at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, ProviderInfo& provider, CmdletProvider& providerInstance)
                                                     at System.Management.Automation.PSCmdlet.GetResolvedProviderPathFromPSPath(String path, ProviderInfo& provider)
                                                     at Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.CmdletHelper.ResolvePSPath(PSCmdlet cmdlet, String path)
                                                     at Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.CmdletHelper.ResolvePSPaths(PSCmdlet cmdlet, ICollection`1 paths)
                    SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
                    ErrorRecord                    : 
                        Exception             : 
                            Type                           : System.Management.Automation.RemoteException
                            SerializedRemoteException      : System.Management.Automation.ItemNotFoundException: Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
                                                             at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider provider, CmdletProviderContext context)
                                                             at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletProvider& providerInstance)
                                                             at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, CmdletProvider& providerInstance)
                                                             at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, ProviderInfo& provider, CmdletProvider& providerInstance)
                                                             at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, ProviderInfo& provider, CmdletProvider& providerInstance)
                                                             at System.Management.Automation.PSCmdlet.GetResolvedProviderPathFromPSPath(String path, ProviderInfo& provider)
                                                             at Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.CmdletHelper.ResolvePSPath(PSCmdlet cmdlet, String path)
                                                             at Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.CmdletHelper.ResolvePSPaths(PSCmdlet cmdlet, ICollection`1 paths)
                            SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
                            ErrorRecord                    : 
                                Exception             : 
                                    Type                           : System.Management.Automation.RemoteException
                                    SerializedRemoteException      : System.Management.Automation.ItemNotFoundException: Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
                                                                     at System.Management.Automation.LocationGlobber.ExpandMshGlobPath(String path, Boolean allowNonexistingPaths, PSDriveInfo drive, ContainerCmdletProvider provider, CmdletProviderContext context)
                                                                     at System.Management.Automation.LocationGlobber.ResolveDriveQualifiedPath(String path, CmdletProviderContext context, Boolean allowNonexistingPaths, CmdletProvider& providerInstance)
                                                                     at System.Management.Automation.LocationGlobber.GetGlobbedMonadPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, CmdletProvider& providerInstance)
                                                                     at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, CmdletProviderContext context, ProviderInfo& provider, CmdletProvider& providerInstance)
                                                                     at System.Management.Automation.LocationGlobber.GetGlobbedProviderPathsFromMonadPath(String path, Boolean allowNonexistingPaths, ProviderInfo& provider, CmdletProvider& providerInstance)
                                                                     at System.Management.Automation.PSCmdlet.GetResolvedProviderPathFromPSPath(String path, ProviderInfo& provider)
                                                                     at Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.CmdletHelper.ResolvePSPath(PSCmdlet cmdlet, String path)
                                                                     at Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.CmdletHelper.ResolvePSPaths(PSCmdlet cmdlet, ICollection`1 paths)
                                    SerializedRemoteInvocationInfo : System.Management.Automation.InvocationInfo
                                    ErrorRecord                    : …
                                    Message                        : Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
                                    HResult                        : -2146233087
                                TargetObject          : NoSuch.exe
                                CategoryInfo          : InvalidArgument: (NoSuch.exe:String) [Get-AppLockerFileInformation], ItemNotFoundException
                                FullyQualifiedErrorId : CmdletHelper-FailedResolvingPSPath,Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.GetAppLockerFileInformationCmdlet
                            Message                        : Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
                            HResult                        : -2146233087
                        TargetObject          : NoSuch.exe
                        CategoryInfo          : InvalidArgument: (NoSuch.exe:String) [Get-AppLockerFileInformation], ItemNotFoundException
                        FullyQualifiedErrorId : CmdletHelper-FailedResolvingPSPath,Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.GetAppLockerFileInformationCmdlet
                    Message                        : Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
                    HResult                        : -2146233087
                TargetObject          : NoSuch.exe
                CategoryInfo          : InvalidArgument: (NoSuch.exe:String) [Get-AppLockerFileInformation], ItemNotFoundException
                FullyQualifiedErrorId : CmdletHelper-FailedResolvingPSPath,Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.GetAppLockerFileInformationCmdlet
            Message                        : Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
            HResult                        : -2146233087
        TargetObject          : NoSuch.exe
        CategoryInfo          : InvalidArgument: (NoSuch.exe:String) [Get-AppLockerFileInformation], ItemNotFoundException
        FullyQualifiedErrorId : CmdletHelper-FailedResolvingPSPath,Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.GetAppLockerFileInformationCmdlet
    Message                        : Cannot find path 'C:\Users\HotCakeX\NoSuch.exe' because it does not exist.
    HResult                        : -2146233087
TargetObject          : NoSuch.exe
CategoryInfo          : InvalidArgument: (NoSuch.exe:String) [Get-AppLockerFileInformation], ItemNotFoundException
FullyQualifiedErrorId : CmdletHelper-FailedResolvingPSPath,Microsoft.Security.ApplicationId.PolicyManagement.Cmdlets.GetAppLockerFileInformationCmdlet

Environment data

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

Visuals

No response

About this issue

  • Original URL
  • State: closed
  • Created 10 months ago
  • Comments: 15 (5 by maintainers)

Most upvoted comments

Looks like this regressed in preview.2. Looking at the changes. Found the issue, working on a PR.

@HotCakeX, interesting: On my W11 22H2 ARM64 machine running PowerShell 7.4.0-preview.5, Import-PSSession works normally, and after does print (i.e. reproducing the problem).

It occurred to me that, returning to the Windows Compatibility Feature root of your issue, the simpler repro (which doesn’t require elevation) is:

Get-AppLockerFileInformation NoSuch.exe -ErrorAction Stop; 'after'

For me, after only prints in PowerShell 7.4.0-preview.5, consistent with the Import-PSSession repro.

If you’re seeing different symptoms, we’ll have to wait for someone with deeper insights to weigh in.

I think I’ve added the right labels here

/cc @PaulHigin Could you please comment?

@iSazonov - FYI Paul has retired so may not respond to this thread

Interestingly the AppLocker module is apparently untested with the Compatibility layer as per this doc not that should really make much of a difference with

I can however replicate this with the latest daily build with the ActiveDirectory Module too

Get-ADUser -Filter * -ErrorAction Stop ; 'After'

Will flag this as possible blocker for 7.4

@mklement0

The problem with PSSsession must’ve been due to my network configurations, but I can reproduce this last one which is very straightforward and easy. I’ll change the title to those you suggested earlier.

image

image

Indeed, @HotCakeX. I thought I’d seen the same problem in Windows PowerShell in the past, but I cannot reproduce it anymore there.

Based on my informal tests with the repro below, the problematic combinations appear to be:

  • Calling from a v7.4-preview.5 session…
  • to Windows PowerShell or (via -ConfigurationName) to v7.3-.
  • By contrast, targeting the same v7.4-preview.5 version seems to work fine. Here’s a minimal repro that uses “loopback remoting”, so the code must be run with elevation:
#requires -RunAsAdministrator

# Import 'Get-Item' from Windows PowerShell via implicit remoting.
Import-PSSession -CommandName Get-Item -AllowClobber (New-PSSession -ComputerName localhost)

# Provoke a non-terminating error and elevate it with -ErrorAction Stop; 'after' should NOT print.
Get-Item nosuch -ErrorAction Stop; 'after'

Note that the above also implies that the problem is unrelated to whether you’re calling from a module or not, so I suggest updating the title; what it comes down to:

  • Passing -ErrorAction Stop to an implicitly remoting function is no longer honored…
  • … when calling from v7.4-preview.5, depending on the version / edition being remoted to.

@mklement0 Thanks for confirming, I think it’s a regression, like something is broken in PowerShell 7.4.0-preview.5.

Hope this gets fixed before it’s released to the stable channel.

@HotCakeX, excellent point: I wasn’t aware of the discrepancy, and I didn’t expect it. Indeed, v7.2.x and v7.3.6 do not exhibit the symptom.

At this point, I have no explanation.

It looks like this function is remoted from PowerShell 7 to PowerShell 5 to use a Windows Module which otherwise wouldn’t work, and the remoted function doesn’t throw an error is that is catchable. It needs someone who knows more about the compatibility feature to say if that is really the case.