How to execute Powershell command from CommandPrompt? One line!

pstein

Extraordinary Member
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
 

Neemobeer

Windows Forum Team
Staff member
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}"
 

pstein

Extraordinary Member
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."
 

Neemobeer

Windows Forum Team
Staff member
Looks like the -command {<command>} format doesn't redirect to stdout use -command "& {<command>}" instead
 
Top