Run Powershell Script
PowerShell is an open-source shell and scripting language built on top of Microsoft .NET technology. It aims to help tech pros that may not be software developers build efficient scripts and tools to help them do their job better. It’s easy to create Powershell scripts, but it can be confusing to figure out how to run them. Here are some simple steps you can follow to run your scripts and make sure everything is working correctly.
How to run a PowerShell script?
Method 1: Run as an Administrator
- When you run any PowerShell script in an elevated session, it runs as an administrator. Or you can run a PowerShell script file as an administrator with the following command:
Start-Process powershell -verb runas -ArgumentList “-file C:\PS\Scripts\myPSScript.ps1”
- You can open the console as an administrator with the following command:
powershell Start-Process powershell -Verb runAs
Method 2: Run from CMD
If you can’t or would rather not run scripts via the PowerShell as Administrator, you can also do so with the good ol’ command line (command prompt).
- Type the following command to run the script and press Enter:
- In the above command, change “PATH\TO\SCRIPT” to the location of your script.
For example, this command runs a script stored in the Downloads folder:& “C:\Users\username\Downloads\first_script.ps1”
Method 3: Run Powershell ISE
- Open a Powershell file in the editor, right-click it and choose Edit
- To run a script in PowerShell ISE simply click on the green play button in the toolbar. The results of the scripts are displayed in the console: