Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,29 @@ internal class CommandLineParameterParser
private const int MaxPipePathLengthMacOS = 104;

internal static string[] validParameters = {
"version",
"nologo",
"noexit",
#if STAMODE
"sta",
"mta",
#endif
"noprofile",
"noninteractive",
"inputformat",
"outputformat",
"windowstyle",
"encodedcommand",
"command",
"configurationname",
"file",
"custompipename",
"encodedcommand",
"executionpolicy",
"command",
"settingsfile",
"file",
"help",
"workingdirectory",
"inputformat",
"loadprofile",
"noexit",
"nologo",
"noninteractive",
"noprofile",
"outputformat",
"removeworkingdirectorytrailingcharacter",
"custompipename"
"settingsfile",
"version",
"windowstyle",
"workingdirectory"
};

internal CommandLineParameterParser(PSHostUserInterface hostUI, string bannerText, string helpText)
Expand Down Expand Up @@ -742,6 +743,10 @@ private void ParseHelper(string[] args)
_noExit = true;
noexitSeen = true;
}
else if (MatchSwitch(switchKey, "loadprofile", "l"))
{
_skipUserInit = false;
}
else if (MatchSwitch(switchKey, "noprofile", "nop"))
{
_skipUserInit = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Type 'help' to get help.</value>
[-ConfigurationName &lt;string&gt;] [-CustomPipeName &lt;string&gt;]
[-EncodedCommand &lt;Base64EncodedCommand&gt;]
[-ExecutionPolicy &lt;ExecutionPolicy&gt;] [-InputFormat {Text | XML}]
[-Interactive] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
[-Interactive] [-LoadProfile] [-NoExit] [-NoLogo] [-NonInteractive] [-NoProfile]
[-OutputFormat {Text | XML}] [-Version] [-WindowStyle &lt;style&gt;]
[-WorkingDirectory &lt;directoryPath&gt;]

Expand Down Expand Up @@ -176,11 +176,11 @@ All parameters are case-insensitive.</value>
Example: pwsh -ConfigurationName AdminRoles

-CustomPipeName
Specifies the name to use for an additional IPC server (named pipe) used for debugging
Specifies the name to use for an additional IPC server (named pipe) used for debugging
and other cross-process communication. This offers a predictable mechanism for connecting
to other PowerShell instances. Typically used with the CustomPipeName parameter on Enter-PSHostProcess.

Example:
Example:
# PowerShell instance 1
pwsh -CustomPipeName mydebugpipe
# PowerShell instance 2
Expand Down Expand Up @@ -224,6 +224,9 @@ All parameters are case-insensitive.</value>
-Interactive | -i
Present an interactive prompt to the user. Inverse for NonInteractive parameter.

-LoadProfile | -l
Load the PowerShell profiles. This is the default behavior even if this is not specified.

-NoExit | -noe
Does not exit after running startup commands.

Expand Down
36 changes: 36 additions & 0 deletions test/powershell/Host/ConsoleHost.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,42 @@ Describe "ConsoleHost unit tests" -tags "Feature" {
}
}

Context "-LoadProfile Commandline switch" {
BeforeAll {
if (Test-Path $profile) {
Remove-Item -Path "$profile.backup" -ErrorAction SilentlyContinue
Rename-Item -Path $profile -NewName "$profile.backup"
}

Set-Content -Path $profile -Value "'profile-loaded'" -Force
}

AfterAll {
Remove-Item -Path $profile -ErrorAction SilentlyContinue

if (Test-Path "$profile.backup") {
Rename-Item -Path "$profile.backup" -NewName $profile
}
}

It "Verifies pwsh will accept <switch> switch" -TestCases @(
@{ switch = "-l"},
@{ switch = "-loadprofile"}
){
param($switch)

if (Test-Path $profile) {
& pwsh $switch -command exit | Should -BeExactly "profile-loaded"
}
else {
# In CI, may not be able to write to $profile location, so just verify that the switch is accepted
# and no error message is in the output
& pwsh $switch -command exit *>&1 | Should -BeNullOrEmpty
}
}
}


Context "-SettingsFile Commandline switch" {

BeforeAll {
Expand Down