diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs
index 6eb9059df18..51db1e5f36c 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs
@@ -3,6 +3,7 @@
using System.Management.Automation;
using System.Management.Automation.Runspaces;
+using System.Runtime.CompilerServices;
namespace Microsoft.PowerShell
{
@@ -21,11 +22,29 @@ class ConsoleShell
/// An integer value which should be used as exit code for the process.
public static int Start(string bannerText, string helpText, string[] args)
{
+ return Start(InitialSessionState.CreateDefault2(), bannerText, helpText, args);
+ }
+
+ /// Entry point in to ConsoleShell. Used to create a custom Powershell console application
+ /// InitialSessionState to be used by the ConsoleHost.
+ /// Banner text to be displayed by ConsoleHost.
+ /// Help text for the shell.
+ /// Commandline parameters specified by user.
+ /// An integer value which should be used as exit code for the process.
+ public static int Start(InitialSessionState initialSessionState, string bannerText, string helpText, string[] args)
+ {
+ if (initialSessionState == null)
+ {
+ throw PSTraceSource.NewArgumentNullException(nameof(initialSessionState));
+ }
+
if (args == null)
{
- throw PSTraceSource.NewArgumentNullException("args");
+ throw PSTraceSource.NewArgumentNullException(nameof(args));
}
+ ConsoleHost.DefaultInitialSessionState = initialSessionState;
+
return ConsoleHost.Start(bannerText, helpText, args);
}
}
diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs
index 4094da9931d..b400f7ed0f4 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs
@@ -63,8 +63,6 @@ public static int Start(string consoleFilePath, [MarshalAs(UnmanagedType.LPArray
System.Diagnostics.Debugger.Break();
}
#endif
- ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
-
int exitCode = 0;
try
{