How to Run PowerShell Script From CMD
Last Updated :
11 Mar, 2025
Executing PowerShell scripts from the Command Prompt (CMD) is a common task for developers and system administrators, essential for automation and integration.
In this blog post, we’ll guide you through the steps to run a PowerShell script using CMD, covering key commands and their functions to help you automate tasks and combine scripts seamlessly. Let’s explore how running PowerShell scripts from CMD can simplify your work
How to Run PowerShell Script From CMDHow to Enter the PowerShell Mode in Command Prompt
- PowerShell offers advanced scripting capabilities, while CMD provides a convenient interface for triggering these scripts. Here's how you can do it.
Step 1: Access the Command Prompt
cmd as adminStep 2: Type PowerShell in the Command Line
- Once you enter the command line, simply type "PowerShell" and hit the enter button.
Note: Once you run "PowerShell" in the command line, you'll notice that new line will now starts with "PS" which indicates that Windows PowerShell is active now.

Run PowerShell Scripts from Command Line - 5 Syntax
- To perform PowerShell script execution on CMD, the following methods can be used. We will start with the simple Script File Path process.
1. Use Script Path to Run PowerShell Script
- Assume you have a script file, named (shell.ps1) located in C:\ so you can get the entire details using the following command:
powershell -File "C:\Scripts\example.ps1"

2. Execute PowerShell Scripts from CMD using PowerShell Command
- If you are getting errors from the above process, the following command could be a relief. Execute the command like it is mentioned to get details without any error.
powershell.exe <Enter Full Path>

3. Passing Arguments to the Script
- You can also pass arguments to the PowerShell script using command line. Here's an example:
Input:
param (
[string]$Name,
[int]$Age
)
Write-Host "Hello, $Name! You are $Age years old."
Output:
Run PowerShell script from the command line with parameters4. Run Inline PowerShell Commands
- This method is suitable where instead of creating a script file, run inline commands from command line PowerShell. Here's an example for better understanding:
Input:
powershell -Command "Write-Host 'Hello, World!'"
Output:
Hello, World!5. Run PowerShell Script from Command Line as Administrator
- You will be required to have an administrator access to run certain scripts. Here's an example of a script that requires elevated privileges:
Input:
powershell -File "C:\Scripts\example.ps1"
Output:
Run PowerShell script from command line with parameters to configure Exchange Mailbox- Running a PowerShell script from Command Line with parameters is a straightforward process that can enhance your ability to manage tasks and automate processes efficiently.
Tips & Tricks: Run PowerShell Scripts
1. Always use "Alias"
- Run PowerShell script to create a batch (.bat) file using command prompt:
@echo off
powershell -File "C:\Scripts\example.ps1"
2. Log Script Output
- Ensure to redirect output to a file for debugging:
powershell -File "C:\Scripts\example.ps1" > output.log
3. Use Windows Task Scheduler for Script Automation
- You can also use Windows Task Scheduler to automate the running PowerShell scripts with parameters. Navigate it via Start > Control Panel > Administrative Tools > Task Scheduler.
Conclusion
Knowing how to run PowerShell scripts from command line as administrator can greatly enhance your workflow, especially when working in environments that require the integration of multiple scripting languages.
By following the steps outlined in this guide, you can easily execute PowerShell scripts in CMD and streamline your tasks. Whether you're new to scripting or an experienced user, this method offers a straightforward way to leverage the power of PowerShell through the Command Prompt.
Similar Reads
How to Run Postman Scripts from Newman CLI Commands Postman is an API development tool that allows developers to create, test, and manage APIs effortlessly. This helps in simplifying the testing and validation of APIs during the development process. In simple terms, it is an API that acts as a bridge that allows the different applications to communic
5 min read
How to run TestNG from command line? Running TestNG from the command line is a powerful technique for managing your automated tests efficiently. TestNG is a popular testing framework that provides various features for running and configuring tests. While IDE-based execution is common, using the command line offers greater flexibility a
4 min read
How to Run Remote Command Execution on Powershell? From the Command Line Interface on Windows, the Command Prompt Application first comes to your mind. However, another great Command Line Interface is Windows Terminal i.e. Windows Powershell which can be also useful. If you want to perform Remote Command Execution on some other Remote Computers, the
5 min read
How to Run Powershell x86 Inside Visual Studio Code x64? If you need to run PowerShell x86 in Visual Studio Code, this guide will help you set up your PowerShell x86 configuration in VS Code. Despite Visual Studio Code being a 64-bit application, you can still execute PowerShell x86 in VS Code to ensure compatibility with 32-bit scripts or modules. We'll
4 min read
How To Run Bash Script In Linux? Bash scripts, also called shell scripts, are programs that help automate tasks by storing a series of commands that often go together, like updates or upgrades. These scripts make it easier to perform tasks automatically instead of typing each command manually. After creating a Bash script, you can
6 min read
How to Update Azure Subscription Tags using PowerShell? Pre-requisite: Azure Updating Azure subscription tags using PowerShell is a straightforward process that allows you to easily manage and organize resources in your subscription. With PowerShell, you can add, modify, or remove tags from individual resources or apply tags to multiple resources simulta
2 min read