diff --git a/src/System.Management.Automation/engine/MshCmdlet.cs b/src/System.Management.Automation/engine/MshCmdlet.cs
index 628ee8b461..e9ee4ec2f6 100644
--- a/src/System.Management.Automation/engine/MshCmdlet.cs
+++ b/src/System.Management.Automation/engine/MshCmdlet.cs
@@ -686,7 +686,7 @@ namespace System.Management.Automation
///
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 @@ namespace System.Management.Automation
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 d6d6436f4f..05ce39c8b5 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:()'
+ }
+ }
}