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

John Savill

December 3, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today

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 SettingsAdministrator> 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 SettingsAdministrator> get-process | stop-process -confirm

ConfirmAre 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

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like