- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to run PowerShell commands from the command prompt?
To run Powershell commands from the command prompt or cmd, we need to call the PowerShell process PowerShell.exe.
Example
See the sample example,
C:\> Powershell.exe -Command "Write-Output 'Hello world'" Hello world
Similarly, you can call any command. We will use another example to get service information
C:\> Powershell.exe -Command "Get-Service Spooler" Status Name DisplayName ------ ---- ----------- Running Spooler Print Spooler
To run multiple commands,
C:\> Powershell.exe -Command "Stop-Service Spooler -verbose -passthru; Start-Service Spooler -verbose -passthru"
Output
VERBOSE: Performing the operation "Stop-Service" on target "Print Spooler (Spooler)". Status Name DisplayName ------ ---- ----------- Stopped Spooler Print Spooler VERBOSE: Performing the operation "Start-Service" on target "Print Spooler (Spooler)". Running Spooler Print Spooler
The above command is similar to,
C:\> Powershell.exe Invoke-Command -scriptblock { "Stop-Service Spooler -verbose - passthru; Start-Service Spooler -verbose -passthru" }
- Related Articles
- How to run a PowerShell script from the command prompt?
- How to run PowerShell commands in Background?
- How to compile & run a Java program using Command Prompt?
- How to run a JAR file through command prompt in java?
- How to run Invoke-Command in PowerShell Workflow?
- How to run TestNG from command line?
- How to run Python functions from command line?
- How to use PowerShell Help commands?
- How can I execute JavaScript at the command prompt?
- How to get/resolve the command from the alias in PowerShell?
- After connecting to MySQL server how can we select a database from command prompt?
- How to Re-run Last Executed Commands in Linux?
- How To Run Commands On Multiple Remote Servers Simultaneously
- How to Run Postman Collection on Jenkins using Newman Commands?
- Getting MySQL path in command prompt

Advertisements