Adding positional parameter for ScriptBlock when using Invoke-Command with SSH (#10721)

This commit is contained in:
Marco Schmid 2019-10-10 20:29:31 +02:00 committed by Aditya Patwardhan
parent 36bc894d9b
commit 0f9ca32d6d
2 changed files with 13 additions and 3 deletions

View file

@ -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")]

View file

@ -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
}
}