8000 Fix implicit remoting proxy cmdlets to act on common parameters by SteveL-MSFT · Pull Request #20367 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Fix implicit remoting proxy cmdlets to act on common parameters #20367

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1300,13 +1300,23 @@ private ParameterMetadata RehydrateParameterMetadata(PSObject deserializedParame
parameterType);
}

private static bool IsProxyForCmdlet(Dictionary<string, ParameterMetadata> parameters)
private bool IsProxyForCmdlet(Dictionary<string, ParameterMetadata> parameters)
{
// we are not sending CmdletBinding/DefaultParameterSet over the wire anymore
// we need to infer IsProxyForCmdlet from presence of all common parameters

foreach (string commonParameterName in Cmdlet.CommonParameters)
// need to exclude `ProgressAction` which may not exist for downlevel platforms
bool isDownLevelRemote = Session.Runspace is RemoteRunspace remoteRunspace
&& remoteRunspace.ServerVersion is not null
&& remoteRunspace.ServerVersion <= new Version(7, 3);

foreach (string commonParameterName in CommonParameters)
{
if (isDownLevelRemote && commonParameterName == "ProgressAction")
{
continue;
}

if (!parameters.ContainsKey(commonParameterName))
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1532,4 +1532,15 @@ Describe "WinCompat importing should check availablity of built-in modules" -Tag
$result[4] | Should -BeExactly 'ConvertFrom-String'
$result[5] | Should -BeExactly 'CFS'
}

It 'ErrorAction should be used for cmdlet' {
try {
$out = Invoke-Expression 'get-AppLockerFileInformation NoSuch.exe -ErrorAction Stop; "after"'
}
catch {
# do nothing as we expect an error, but execution should not continue
}

$out | Should -Not -Contain 'after'
}
}
0