Windows 7 How to execute Powershell command from CommandPrompt? One line!

pstein

Extraordinary Member
Joined
Mar 20, 2010
I want to execute a PowerShell command from Command Prompt.
This should be done by entering ONE command!

I DO NOT want to start PowerShell first and then enter the PowerShell command.

Instead I want to enter something like

powershell.exe -command "......."

How does that work in detail on Win7?

Peter
 
powershell.exe -command {command1;command2;command3}
or
powershell.exe -command "&{command1;command2;command3} "

Examples
PowerShell -Command {Get-EventLog -LogName security}
PowerShell -Command "& {Get-EventLog -LogName security}"
 
Why does

Powershell -Command {Get-HotFix | Sort InstalledOn -Desc}

NOT work?

When I enter this in CmdPrompt then the output is:

"Input file specified two times."
 
Looks like the -command {<command>} format doesn't redirect to stdout use -command "& {<command>}" instead
 
Back
Top Bottom