PowerShell scripts are text files with ".ps1" extensions that contain PowerShell commands. Starting with Windows Server 2008, PowerShell is built into the OS. For earlier OS versions, you will need to download PowerShell at Microsoft PowerShell Site and install it.
To run ps1 scripts, you first need to enable scripts by running:
Otherwise, you will get this error message:
File <script> cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
The most common way to run PowerShell scripts is from Windows PowerShell command prompt. You must specify a path to the script to run it. If the script is in your current folder, then you can run it with:
If the script is in another folder, you need specify the full path:
How to enable PowerShell scripts
- Open a PowerShell command prompt and type Set-ExecutionPolicy RemoteSigned
- You will be asked if you are sure
- Select ‘Y’ and hit <enter>
You are now setup to run scripts on your machine. Note that if you use a 64 bit machine then you need to set the policy for both x86 and x64 PowerShell. If at any time you want to switch back to not allowing scripts, run “Set-ExecutionPolicy Restricted”.