Adding positional parameter for ScriptBlock when using Invoke-Command with SSH (#10721)
This commit is contained in:
parent
36bc894d9b
commit
0f9ca32d6d
|
@ -531,9 +531,11 @@ namespace Microsoft.PowerShell.Commands
|
|||
[Parameter(Position = 1,
|
||||
Mandatory = true,
|
||||
ParameterSetName = InvokeCommandCommand.ContainerIdParameterSet)]
|
||||
[Parameter(Mandatory = true,
|
||||
[Parameter(Position = 1,
|
||||
Mandatory = true,
|
||||
ParameterSetName = InvokeCommandCommand.SSHHostParameterSet)]
|
||||
[Parameter(Mandatory = true,
|
||||
[Parameter(Position = 1,
|
||||
Mandatory = true,
|
||||
ParameterSetName = InvokeCommandCommand.SSHHostHashParameterSet)]
|
||||
[ValidateNotNull]
|
||||
[Alias("Command")]
|
||||
|
|
|
@ -13,7 +13,15 @@ Describe "SSH Remoting Cmdlet Tests" -Tags "Feature" {
|
|||
}
|
||||
|
||||
It "Invoke-Command HostName parameter set should throw error for invalid key path" {
|
||||
{ Invoke-Command -HostName localhost -UserName User -KeyFilePath NoKeyFile -ScriptBlock {1} } |
|
||||
{ Invoke-Command -HostName localhost -UserName User -KeyFilePath NoKeyFile -ScriptBlock { 1 } } |
|
||||
Should -Throw -ErrorId "PathNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand"
|
||||
}
|
||||
|
||||
It "Invoke-Command should support positional parameter ScriptBlock when using parameter set '<ParameterSetName>'" -TestCases @{ParameterSetName = 'SSHHost' }, @{ParameterSetName = 'SSHHostHashParam' } {
|
||||
param ([string]$ParameterSetName)
|
||||
$commandInfo = Get-Command -Name Invoke-Command
|
||||
$sshParameterSet = $commandInfo.ParameterSets | Where-Object { $_.Name -eq $ParameterSetName }
|
||||
$scriptBlockPosition = $sshParameterSet.Parameters | Where-Object { $_.Name -eq 'ScriptBlock' } | Select-Object -ExpandProperty Position
|
||||
$scriptBlockPosition | Should -Be 1
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue