Skip to content

Commit d73e974

Browse files
SteveL-MSFTdaxian-dbw
authored andcommitted
Fix incorrect position of a parameter which resulted in the args passed as input instead of as args (PowerShell#4963)
1 parent fa170a7 commit d73e974

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/System.Management.Automation/engine/MshCmdlet.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ public Collection<PSObject> InvokeScript(string script)
686686
/// <exception cref="FlowControlException"></exception>
687687
public Collection<PSObject> InvokeScript(string script, params object[] args)
688688
{
689-
return InvokeScript(script, true, PipelineResultTypes.None, args);
689+
return InvokeScript(script, true, PipelineResultTypes.None, null, args);
690690
}
691691

692692
/// <summary>
@@ -712,7 +712,12 @@ public Collection<PSObject> InvokeScript(
712712
try
713713
{
714714
_context.EngineSessionState = sessionState.Internal;
715-
return InvokeScript(scriptBlock, false, PipelineResultTypes.None, null, args);
715+
return InvokeScript(
716+
sb:scriptBlock,
717+
useNewScope:false,
718+
writeToPipeline:PipelineResultTypes.None,
719+
input:null,
720+
args:args);
716721
}
717722
finally
718723
{

test/powershell/engine/Api/BasicEngine.Tests.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@ Describe 'Basic engine APIs' -Tags "CI" {
1313
$result[0].PSSnapIn.Name | Should Be "Microsoft.WSMan.Management"
1414
}
1515
}
16+
17+
Context 'executioncontext' {
18+
It 'args are passed correctly' {
19+
$result = $ExecutionContext.SessionState.InvokeCommand.InvokeScript('"`$args:($args); `$input:($input)"', 1, 2, 3)
20+
$result | Should BeExactly '$args:(1 2 3); $input:()'
21+
}
22+
}
1623
}

0 commit comments

Comments
 (0)