diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs
index 6023199fcc..f6d7b8c235 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Process.cs
@@ -1658,7 +1658,7 @@ namespace Microsoft.PowerShell.Commands
///
/// This class implements the Start-process command
///
- [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
{
@@ -2051,6 +2051,9 @@ namespace Microsoft.PowerShell.Commands
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);
diff --git a/src/Microsoft.PowerShell.Commands.Management/resources/ProcessResources.resx b/src/Microsoft.PowerShell.Commands.Management/resources/ProcessResources.resx
index 558f22cafa..a95f7d3720 100644
--- a/src/Microsoft.PowerShell.Commands.Management/resources/ProcessResources.resx
+++ b/src/Microsoft.PowerShell.Commands.Management/resources/ProcessResources.resx
@@ -132,6 +132,9 @@
{0} ({1})
+
+ {0} {1}
+
Cannot enumerate the modules of the "{0}" process.
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1
index 6a52123ec0..09ad4e1f4f 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Start-Process.Tests.ps1
@@ -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" {