Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -2740,7 +2740,7 @@ function Get-PSImplicitRemotingClientSideParameters

$clientSideParameters = @{}

$parametersToLeaveRemote = 'ErrorAction', 'WarningAction', 'InformationAction'
$parametersToLeaveRemote = 'ErrorAction', 'WarningAction', 'InformationAction', 'ProgressAction'

Modify-PSImplicitRemotingParameters $clientSideParameters $PSBoundParameters 'AsJob'
if ($proxyForCmdlet)
Expand Down
21 changes: 21 additions & 0 deletions src/System.Management.Automation/engine/CommonCommandParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,27 @@ public ActionPreference InformationAction
set { _commandRuntime.InformationPreference = value; }
}

/// <summary>
/// Gets or sets the value of the ProgressAction parameter for the cmdlet.
/// </summary>
/// <remarks>
/// This parameter tells the command what to do when a progress record occurs.
/// </remarks>
/// <!--
/// NOTE: The "proga" alias name does not follow the same alias naming convention used
/// with other common parameter aliases that control stream functionality; however,
/// "pa" was already taken as a parameter alias in other commands when this parameter
/// was added to PowerShell, so "proga" was chosen instead.
/// -->
[Parameter]
[Alias("proga")]
public ActionPreference ProgressAction
{
get { return _commandRuntime.ProgressPreference; }

set { _commandRuntime.ProgressPreference = value; }
}

/// <summary>
/// Gets or sets the value of the ErrorVariable parameter for the cmdlet.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/System.Management.Automation/engine/InternalCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,11 @@ public void Dispose()
private void InitParallelParameterSet()
{
// The following common parameters are not (yet) supported in this parameter set.
// ErrorAction, WarningAction, InformationAction, PipelineVariable.
// ErrorAction, WarningAction, InformationAction, ProgressAction, PipelineVariable.
if (MyInvocation.BoundParameters.ContainsKey(nameof(CommonParamSet.ErrorAction)) ||
MyInvocation.BoundParameters.ContainsKey(nameof(CommonParamSet.WarningAction)) ||
MyInvocation.BoundParameters.ContainsKey(nameof(CommonParamSet.InformationAction)) ||
MyInvocation.BoundParameters.ContainsKey(nameof(CommonParamSet.ProgressAction)) ||
MyInvocation.BoundParameters.ContainsKey(nameof(CommonParamSet.PipelineVariable)))
{
ThrowTerminatingError(
Expand Down
8 changes: 5 additions & 3 deletions src/System.Management.Automation/engine/MshCommandRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3330,7 +3330,7 @@ internal ActionPreference ProgressPreference
{
get
{
if (_isProgressPreferenceSet)
if (IsProgressActionSet)
return _progressPreference;

if (!_isProgressPreferenceCached)
Expand All @@ -3351,12 +3351,14 @@ internal ActionPreference ProgressPreference
}

_progressPreference = value;
_isProgressPreferenceSet = true;
IsProgressActionSet = true;
}
}

private ActionPreference _progressPreference = InitialSessionState.DefaultProgressPreference;
private bool _isProgressPreferenceSet = false;

internal bool IsProgressActionSet { get; private set; } = false;

private bool _isProgressPreferenceCached = false;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ static ReflectionParameterBinder()
v ??= LanguagePrimitives.ThrowInvalidCastException(null, typeof(ActionPreference));
((CommonParameters)o).InformationAction = (ActionPreference)v;
});
s_setterMethods.TryAdd(Tuple.Create(typeof(CommonParameters), "ProgressAction"),
(o, v) =>
{
v ??= LanguagePrimitives.ThrowInvalidCastException(null, typeof(ActionPreference));
((CommonParameters)o).ProgressAction = (ActionPreference)v;
});
s_setterMethods.TryAdd(Tuple.Create(typeof(CommonParameters), "Verbose"), static (o, v) => ((CommonParameters)o).Verbose = (SwitchParameter)v);
s_setterMethods.TryAdd(Tuple.Create(typeof(CommonParameters), "Debug"), static (o, v) => ((CommonParameters)o).Debug = (SwitchParameter)v);
s_setterMethods.TryAdd(Tuple.Create(typeof(CommonParameters), "ErrorVariable"), static (o, v) => ((CommonParameters)o).ErrorVariable = (string)v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,5 +419,6 @@ internal enum PreferenceVariable
Warning = 13,
Information = 14,
Confirm = 15,
Progress = 16,
}
}
2 changes: 1 addition & 1 deletion src/System.Management.Automation/engine/cmdlet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static HashSet<string> CommonParameters
() =>
{
return new HashSet<string>(StringComparer.OrdinalIgnoreCase) {
"Verbose", "Debug", "ErrorAction", "WarningAction", "InformationAction",
"Verbose", "Debug", "ErrorAction", "WarningAction", "InformationAction", "ProgressAction",
"ErrorVariable", "WarningVariable", "OutVariable",
"OutBuffer", "PipelineVariable", "InformationVariable" };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,11 @@ private void SetPreferenceVariables()
_localsTuple.SetPreferenceVariable(PreferenceVariable.Information, _commandRuntime.InformationPreference);
}

if (_commandRuntime.IsProgressActionSet)
{
_localsTuple.SetPreferenceVariable(PreferenceVariable.Progress, _commandRuntime.ProgressPreference);
}

if (_commandRuntime.IsWhatIfFlagSet)
{
_localsTuple.SetPreferenceVariable(PreferenceVariable.WhatIf, _commandRuntime.WhatIf);
Expand Down
6 changes: 3 additions & 3 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1620,8 +1620,8 @@ dir -Recurse `
It "Test completion with splatted variable" {
$inputStr = 'Get-Content @Splat -P'
$res = TabExpansion2 -inputScript $inputStr -cursorColumn $inputStr.Length
$res.CompletionMatches | Should -HaveCount 4
[string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "-Path,-PipelineVariable,-PSPath,-pv"
$res.CompletionMatches | Should -HaveCount 6
[string]::Join(',', ($res.CompletionMatches.completiontext | Sort-Object)) | Should -BeExactly "-Path,-PipelineVariable,-proga,-ProgressAction,-PSPath,-pv"
}

It "Test completion for HttpVersion parameter name" {
Expand Down Expand Up @@ -2411,7 +2411,7 @@ Describe "WSMan Config Provider tab complete tests" -Tags Feature,RequireAdminOn
@{path = "localhost\plugin"; parameter = "-ru"; expected = "RunAsCredential"},
@{path = "localhost\plugin"; parameter = "-us"; expected = "UseSharedProcess"},
@{path = "localhost\plugin"; parameter = "-au"; expected = "AutoRestart"},
@{path = "localhost\plugin"; parameter = "-pr"; expected = "ProcessIdleTimeoutSec"},
@{path = "localhost\plugin"; parameter = "-proc"; expected = "ProcessIdleTimeoutSec"},
@{path = "localhost\Plugin\microsoft.powershell\Resources\"; parameter = "-re"; expected = "ResourceUri"},
@{path = "localhost\Plugin\microsoft.powershell\Resources\"; parameter = "-ca"; expected = "Capability"}
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Describe "Tests for (error, warning, etc) action preference" -Tags "CI" {
@{ name = "ErrorAction"; argValue = "AutomationNull"; arguments = @{ ErrorAction = [System.Management.Automation.Internal.AutomationNull]::Value } }
@{ name = "WarningAction"; argValue = "AutomationNull"; arguments = @{ WarningAction = [System.Management.Automation.Internal.AutomationNull]::Value } }
@{ name = "InformationAction"; argValue = "AutomationNull"; arguments = @{ InformationAction = [System.Management.Automation.Internal.AutomationNull]::Value } }
@{ name = "ProgressAction"; argValue = "AutomationNull"; arguments = @{ ProgressAction = [System.Management.Automation.Internal.AutomationNull]::Value } }
) {
param($arguments)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ Describe "Experimental Feature Basic Tests - Feature-Enabled" -Tag "CI" {
$command = Get-Command $Name
$command.CommandType | Should -Be $CommandType
## Common parameters + '-Name' + '-SwitchOne' + '-SwitchTwo'
$command.Parameters.Count | Should -Be ($CommonParameterCount + 3)
$command.Parameters.Count | Should -Be ($CommonParameterCount + 3) -Because ($command.Parameters.Keys -join ", ")
$command.ParameterSets.Count | Should -Be 3

& $Name -Name Joe | Should -BeExactly "Hello World Joe."
Expand All @@ -254,7 +254,7 @@ Describe "Experimental Feature Basic Tests - Feature-Enabled" -Tag "CI" {

## Common parameters + '-UserName', '-ComputerName', '-ConfigurationName', '-VMName', '-Port',
## '-Token', '-WebSocketUrl', '-ThrottleLimit' and '-Command'
$command.Parameters.Count | Should -Be ($CommonParameterCount + 9)
$command.Parameters.Count | Should -Be ($CommonParameterCount + 9) -Because ($command.Parameters.Keys -join ", ")
$command.ParameterSets.Count | Should -Be 3

$command.Parameters["UserName"].ParameterSets.Count | Should -Be 1
Expand Down Expand Up @@ -316,7 +316,7 @@ Describe "Experimental Feature Basic Tests - Feature-Enabled" -Tag "CI" {
$command = Get-Command $Name
$command.CommandType | Should -Be $CommandType
## Common parameters + '-ComputerName'
$command.Parameters.Count | Should -Be ($CommonParameterCount + 1)
$command.Parameters.Count | Should -Be ($CommonParameterCount + 1) -Because ($command.Parameters.Keys -join ", ")
$command.Parameters["ComputerName"].ParameterType.FullName | Should -BeExactly "System.String"
$command.Parameters.ContainsKey("SessionName") | Should -BeFalse
}
Expand All @@ -329,7 +329,7 @@ Describe "Experimental Feature Basic Tests - Feature-Enabled" -Tag "CI" {
$command = Get-Command $Name
$command.CommandType | Should -Be $CommandType
## Common parameters + '-ByUrl', '-ByRadio', '-FileName', '-Destination'
$command.Parameters.Count | Should -Be ($CommonParameterCount + 4)
$command.Parameters.Count | Should -Be ($CommonParameterCount + 4) -Because ($command.Parameters.Keys -join ", ")
$command.ParameterSets.Count | Should -Be 2

$command.Parameters["ByUrl"].ParameterSets.Count | Should -Be 1
Expand Down Expand Up @@ -358,7 +358,7 @@ Describe "Experimental Feature Basic Tests - Feature-Enabled" -Tag "CI" {
$command = Get-Command $Name
$command.CommandType | Should -Be $CommandType
## Common parameters + '-Name' (dynamic parameters are not triggered)
$command.Parameters.Count | Should -Be ($CommonParameterCount + 1)
$command.Parameters.Count | Should -Be ($CommonParameterCount + 1) -Because ($command.Parameters.Keys -join ", ")
$command.Parameters["Name"] | Should -Not -BeNullOrEmpty

$command = Get-Command $Name -ArgumentList "Joe"
Expand Down