Add ability to pass InitialSessionState
to the ConsoleShell.Start
(#9802)
This commit is contained in:
parent
89db7505d6
commit
65a3e467cc
2 changed files with 20 additions and 3 deletions
|
@ -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
|
|||
/// <returns>An integer value which should be used as exit code for the process.</returns>
|
||||
public static int Start(string bannerText, string helpText, string[] args)
|
||||
{
|
||||
return Start(InitialSessionState.CreateDefault2(), bannerText, helpText, args);
|
||||
}
|
||||
|
||||
/// <summary>Entry point in to ConsoleShell. Used to create a custom Powershell console application</summary>
|
||||
/// <param name="initialSessionState">InitialSessionState to be used by the ConsoleHost.</param>
|
||||
/// <param name="bannerText">Banner text to be displayed by ConsoleHost.</param>
|
||||
/// <param name="helpText">Help text for the shell.</param>
|
||||
/// <param name="args">Commandline parameters specified by user.</param>
|
||||
/// <returns>An integer value which should be used as exit code for the process.</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,8 +63,6 @@ namespace Microsoft.PowerShell
|
|||
System.Diagnostics.Debugger.Break();
|
||||
}
|
||||
#endif
|
||||
ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
|
||||
|
||||
int exitCode = 0;
|
||||
try
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue