From e8f5888953de74fb6200f6d8997a234b248448dd Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Sat, 30 Sep 2017 10:56:42 -0700 Subject: [PATCH] [feature] fix incorrect position of a parameter which resulted in the args passed as input instead of as args --- src/System.Management.Automation/engine/MshCmdlet.cs | 9 +++++++-- test/powershell/engine/Api/BasicEngine.Tests.ps1 | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/engine/MshCmdlet.cs b/src/System.Management.Automation/engine/MshCmdlet.cs index 628ee8b461e..e9ee4ec2f61 100644 --- a/src/System.Management.Automation/engine/MshCmdlet.cs +++ b/src/System.Management.Automation/engine/MshCmdlet.cs @@ -686,7 +686,7 @@ public Collection InvokeScript(string script) /// public Collection InvokeScript(string script, params object[] args) { - return InvokeScript(script, true, PipelineResultTypes.None, args); + return InvokeScript(script, true, PipelineResultTypes.None, null, args); } /// @@ -712,7 +712,12 @@ public Collection InvokeScript( try { _context.EngineSessionState = sessionState.Internal; - return InvokeScript(scriptBlock, false, PipelineResultTypes.None, null, args); + return InvokeScript( + sb:scriptBlock, + useNewScope:false, + writeToPipeline:PipelineResultTypes.None, + input:null, + args:args); } finally { diff --git a/test/powershell/engine/Api/BasicEngine.Tests.ps1 b/test/powershell/engine/Api/BasicEngine.Tests.ps1 index d6d6436f4f2..05ce39c8b50 100644 --- a/test/powershell/engine/Api/BasicEngine.Tests.ps1 +++ b/test/powershell/engine/Api/BasicEngine.Tests.ps1 @@ -13,4 +13,11 @@ Describe 'Basic engine APIs' -Tags "CI" { $result[0].PSSnapIn.Name | Should Be "Microsoft.WSMan.Management" } } + + Context 'executioncontext' { + It 'args are passed correctly' { + $result = $ExecutionContext.SessionState.InvokeCommand.InvokeScript('"`$args:($args); `$input:($input)"', 1, 2, 3) + $result | Should BeExactly '$args:(1 2 3); $input:()' + } + } }