diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleShell.cs
index 6eb9059df..51db1e5f3 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 @@ namespace Microsoft.PowerShell
/// 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 4094da993..b400f7ed0 100644
--- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs
+++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ManagedEntrance.cs
@@ -63,8 +63,6 @@ namespace Microsoft.PowerShell
System.Diagnostics.Debugger.Break();
}
#endif
- ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
-
int exitCode = 0;
try
{