From b6a619099b029201dac8b08d73302bcc261e4233 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Mon, 18 Jul 2022 18:33:16 -0600 Subject: [PATCH] Fix #16929 do not show profile load time msg with new pwsh parameter (#17535) * Fix #16929 do not show profile load time msg by default This PR adds a new pwsh command line parameter to enable display of the profile load time message. * Switch to an opt-out paramater called -NoProfileLoadTime --- .../host/msh/CommandLineParameterParser.cs | 17 +++++++++++++++++ .../host/msh/ConsoleHost.cs | 2 +- .../resources/ManagedEntranceStrings.resx | 11 +++++++++-- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs index 8d31f35774..0b54bcff24 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/CommandLineParameterParser.cs @@ -186,6 +186,7 @@ namespace Microsoft.PowerShell "nologo", "noninteractive", "noprofile", + "noprofileloadtime", "outputformat", "removeworkingdirectorytrailingcharacter", "settingsfile", @@ -228,6 +229,7 @@ namespace Microsoft.PowerShell WindowStyle = 0x01000000, // -WindowStyle | -w WorkingDirectory = 0x02000000, // -WorkingDirectory | -wd ConfigurationFile = 0x04000000, // -ConfigurationFile + NoProfileLoadTime = 0x08000000, // -NoProfileLoadTime // Enum values for specified ExecutionPolicy EPUnrestricted = 0x0000000100000000, // ExecutionPolicy unrestricted EPRemoteSigned = 0x0000000200000000, // ExecutionPolicy remote signed @@ -463,6 +465,15 @@ namespace Microsoft.PowerShell } } + internal bool NoProfileLoadTime + { + get + { + AssertArgumentsParsed(); + return _noProfileLoadTime; + } + } + internal bool ShowVersion { get @@ -920,6 +931,11 @@ namespace Microsoft.PowerShell _sshServerMode = true; ParametersUsed |= ParameterBitmap.SSHServerMode; } + else if (MatchSwitch(switchKey, "noprofileloadtime", "noprofileloadtime")) + { + _noProfileLoadTime = true; + ParametersUsed |= ParameterBitmap.NoProfileLoadTime; + } else if (MatchSwitch(switchKey, "interactive", "i")) { _noInteractive = false; @@ -1496,6 +1512,7 @@ namespace Microsoft.PowerShell private bool _serverMode; private bool _namedPipeServerMode; private bool _sshServerMode; + private bool _noProfileLoadTime; private bool _showVersion; private string? _configurationFile; private string? _configurationName; diff --git a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs index e8ca269711..949684f487 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs +++ b/src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs @@ -1885,7 +1885,7 @@ namespace Microsoft.PowerShell sw.Stop(); var profileLoadTimeInMs = sw.ElapsedMilliseconds; - if (profileLoadTimeInMs > 500 && s_cpp.ShowBanner) + if (s_cpp.ShowBanner && !s_cpp.NoProfileLoadTime && profileLoadTimeInMs > 500) { Console.Error.WriteLine(ConsoleHostStrings.SlowProfileLoadingMessage, profileLoadTimeInMs); } diff --git a/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx b/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx index 24a6e78ad6..778584742b 100644 --- a/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx +++ b/src/Microsoft.PowerShell.ConsoleHost/resources/ManagedEntranceStrings.resx @@ -149,8 +149,10 @@ [-EncodedCommand <Base64EncodedCommand>] [-ExecutionPolicy <ExecutionPolicy>] [-InputFormat {Text | XML}] [-Interactive] [-MTA] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile] - [-OutputFormat {Text | XML}] [-SettingsFile <filePath>] [-SSHServerMode] [-STA] - [-Version] [-WindowStyle <style>] [-WorkingDirectory <directoryPath>] + [-NoProfileLoadTime] [-OutputFormat {Text | XML}] + [-SettingsFile <filePath>] [-SSHServerMode] [-STA] + [-Version] [-WindowStyle <style>] + [-WorkingDirectory <directoryPath>] pwsh[.exe] -h | -Help | -? | /? @@ -399,6 +401,11 @@ All parameters are case-insensitive. Does not load the PowerShell profiles. +-NoProfileLoadTime + + Hides the PowerShell profile load time text shown at startup when the load + time exceeds 500 milliseconds. + -OutputFormat | -o | -of Determines how output from PowerShell is formatted. Valid values are "Text"