Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


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

30 Oct 2019   #1
pstein

win7pro 64bit
 
 
How to execute Powershell command from CommandPrompt? One line!

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


My System SpecsSystem Spec
.
30 Oct 2019   #2
Paul Black

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 

Hi pstein,

Quote   Quote: Originally Posted by pstein View Post
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?
What do you want the command to produce?
My System SpecsSystem Spec
30 Oct 2019   #3
Paul Black

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 

Hi pstein,

If you wanted to get the bit-type of your OS for example, you could use this in the cmd prompt . . .

Code:
Powershell -Command (Get-WmiObject Win32_OperatingSystem).OSArchitecture
You could also use that in a batch script!

I hope this helps!
My System SpecsSystem Spec
.

31 Oct 2019   #4
pstein

win7pro 64bit
 
 

Why does

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

NOT work?

When I enter this in CmdPrompt/Batch script then the output is:

"Input file specified two times."
My System SpecsSystem Spec
31 Oct 2019   #5
Paul Black

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 

Hi pstein, I do have a batch script that lists all the installed updates!
My System SpecsSystem Spec
31 Oct 2019   #6
iko22

Windows 7 x64, Vista x64, 8.1 smartphone
 
 

Quote   Quote: Originally Posted by pstein View Post
Why does

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

NOT work?

When I enter this in CmdPrompt/Batch script then the output is:

"Input file specified two times."
See Powershell /? for explanation.

You need to create a string that Powershell can execute, so in your case, type:

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

Obvious when you know how!!
My System SpecsSystem Spec
31 Oct 2019   #7
Paul Black

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 

Hi iko22,

Quote   Quote: Originally Posted by iko22 View Post
See Powershell /? for explanation.

You need to create a string that Powershell can execute, so in your case, type:

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

Obvious when you know how!!
You beat me to it!
My System SpecsSystem Spec
.
31 Oct 2019   #8
iko22

Windows 7 x64, Vista x64, 8.1 smartphone
 
 

Quote   Quote: Originally Posted by Paul Black View Post
Hi iko22,



You beat me to it!
Well, youve had two hours.
My System SpecsSystem Spec
31 Oct 2019   #9
Paul Black

Win 7 HP SP1 64-bit Vista HB SP2 32-bit Linux Mint 18.3
 
 

Quote   Quote: Originally Posted by iko22 View Post
Well, youve had two hours.
My System SpecsSystem Spec
Reply

 How to execute Powershell command from CommandPrompt? One line!




Thread Tools




Similar help and support threads
Thread Forum
vbs how to execute a command with quoted parameters
Hi, OS: Win7 64bits Family Can't find the way to fix quoting issue. Suppose in the command prompt this works: "c:\what ever\my program.exe" "d:\some dir\my file.txt" cat 1-2 output "d\some dir\_out.txt"
General Discussion
execute command at boot
Hi, I would like to execute a command at boot and repeat it until it succeeds. Does anyone know how I can achieve that ? For the moment, I run the command in the startup folder, so it does run just after user connection but, as it is a connection demand to another computer by ssh, if the...
General Discussion
Start Command Prompt and automatically execute a few commands
I am learning a programming language, and I frequently use command prompt to compile source codes, but every time I start command prompt I need to manually cd to the correct directory, and then I like to run cls to keep the window clean. I have looked around, but I'm not sure how to phrase a google...
Software
Execute Last Command
scenario : 1. lmb to select a file or folder. 2. rmb to display context menu and choose 'rename'. 3. type new name. 4. lmb to select another file or folder 5. ... is there a way to program a key or a mouse button to automatically execute step 2 above? Or perhaps it's already one of my...
General Discussion


Our Sites

Site Links

About Us

Find Us

Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

Designer Media Ltd

All times are GMT -5. The time now is 03:02.
Twitter Facebook