FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add -WhatIf switch to Start-Process cmdlet by sarithsutha · Pull Request #4735 · PowerShell/PowerShell · GitHub

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

Filter by extension

Filter by extension .cs  (1) .ps1  (1) .resx  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ private string MapReturnCodeToErrorMessage(int returnCode)
/// <summary>
/// This class implements the Start-process command
/// </summary>
[Cmdlet(VerbsLifecycle.Start, "Process", DefaultParameterSetName = "Default", HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135261")]
[Cmdlet(VerbsLifecycle.Start, "Process", DefaultParameterSetName = "Default", SupportsShouldProcess = true, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135261")]
[OutputType(typeof(Process))]
public sealed class StartProcessCommand : PSCmdlet, IDisposable
{
Expand Down Expand Up @@ -2051,6 +2051,9 @@ protected override void BeginProcessing()
startInfo.WindowStyle = _windowstyle;
}

string targetMessage = StringUtil.Format(ProcessResources.StartProcessTarget, startInfo.FileName, startInfo.Arguments.Trim());
if (!ShouldProcess(targetMessage)) { return; }

//Starts the Process
Process process = Start(startInfo);

Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@
<data name="ProcessNameForConfirmation" xml:space="preserve">
<value>{0} ({1})</value>
</data>
<data name="StartProcessTarget" xml:space="preserve">
<value>{0} {1}</value>
</data>
<data name="CouldNotEnumerateModules" xml:space="preserve">
<value>Cannot enumerate the modules of the "{0}" process.</value>
</data>
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ Describe "Start-Process" -Tags @("Feature") {
$process.Name | Should Be "notepad"
$process | Stop-Process
}

It "Should be able to use the -WhatIf switch without performing the actual action" {
$pingOutput = Join-Path $TestDrive "pingOutput.txt"
{ Start-Process -Wait $pingCommand -ArgumentList $pingParam -RedirectStandardOutput $pingOutput -WhatIf -ErrorAction Stop } | Should Not Throw
$pingOutput | Should Not Exist
}

It "Should return null when using -WhatIf switch with -PassThru" {
Start-Process $pingCommand -ArgumentList $pingParam -PassThru -WhatIf | Should Be $null
}
}

Describe "Start-Process tests requiring admin" -Tags "Feature","RequireAdminOnWindows" {
Expand Down

Back | FazBrowse Home | New Git URL