📎 AI Summary:
The thread discusses executing PowerShell commands directly from Command Prompt on Windows 7 using a single command line. The original poster seeks a straightforward method, asking about the correct syntax, with examples provided by a responder. A follow-up question about a specific command failing highlights that using the "-command { }" syntax may not work as expected, and switching to "& { }" is recommended for proper output redirection.

pstein

Extraordinary Member
Joined
Mar 20, 2010
Messages
454
Thread Author #1
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
Joined
Jul 4, 2015
Messages
8,995
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
Joined
Mar 20, 2010
Messages
454
Thread Author #3
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
Joined
Jul 4, 2015
Messages
8,995
Looks like the -command {<command>} format doesn't redirect to stdout use -command "& {<command>}" instead
 

Solution