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 @@ -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
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
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