Skip navigation

How can I determine what a Windows PowerShell command will do? - 04 Dec 2006

A. If you want to run a command in PowerShell but aren't sure what it will do, you can use "-whatif" at the end of the command. For example, if you want to execute the Get-Process command and pipe its output to the Stop-Process command, but you're not sure what it will actually do, you can append -whatif to the end of the command. Doing so shows the output of what would be done, but doesn't actually run the command, as the following example shows:

PS C:\Documents and Settings\Administrator> get-process | stop-process -whatif

What if: Performing operation "Stop-Process" on Target "alg (1872)".
What if: Performing operation "Stop-Process" on Target "certsrv (1036)".
What if: Performing operation "Stop-Process" on Target "csrss (660)".
What if: Performing operation "Stop-Process" on Target "csrss (3028)".
What if: Performing operation "Stop-Process" on Target "ctfmon (1880)".
What if: Performing operation "Stop-Process" on Target "ctfmon (2612)".
What if: Performing operation "Stop-Process" on Target "Dfsr (1864)".
What if: Performing operation "Stop-Process" on Target "dfssvc (1164)".
What if: Performing operation "Stop-Process" on Target "dmadmin (2096)".
What if: Performing operation "Stop-Process" on Target "dns (1204)".
What if: Performing operation "Stop-Process" on Target "explorer (216)".

.. This example shows that if you would run the command without the -whatif, it would stop all processes on the machine (a very fast shutdown). Alternatively, you can use the -confirm inplace of -whatif to be prompted before each action is performed, as this example shows:

PS C:\Documents and Settings\Administrator> get-process | stop-process -confirm
Confirm Are you sure you want to perform this action? Performing operation "Stop-Process" on Target "alg (1872)". \[Y\] Yes \[A\] Yes to All \[N\] No \[L\] No to All \[S\] Suspend \[?\] Help (default is "Y"): l
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish