Executing a command
suggest changeThe -Command parameter is used to specify commands to be executed on launch. It supports multiple data inputs.
-Command <string>
You can specify commands to run at startup as a string. Separate multiple statements with a semicolon (;).
>PowerShell.exe -Command "(Get-Date).ToShortDateString()"
10.09.2016
>PowerShell.exe -Command "(Get-Date).ToShortDateString(); 'PowerShell is fun!'"
10.09.2016
PowerShell is fun!
-Command { scriptblock }
-Command also accepts a script block (one or more statements in braces). That form works when you call powershell.exe from Windows PowerShell, which stringifies the block. It is not a cmd.exe feature.
PS > powershell.exe -Command {
"This can be useful, sometimes..."
(Get-Date).ToShortDateString()
}
This can be useful, sometimes...
10.09.2016
-Command - (standard input)
You can pass commands on standard input with -Command -. The input can come from another command, a file, or a legacy console application. This example is run from PowerShell, where echo is Write-Output:
>echo "Hello World";"Greetings from PowerShell" | PowerShell.exe -NoProfile -Command -
Hello World
Greetings from PowerShell
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents