How to run ps1 scripts

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:

Set-ExecutionPolicy RemoteSigned

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:

.script.ps1

If the script is in another folder, you need specify the full path:

c:scriptsscript.ps1

    How to enable PowerShell scripts

    1. Open a PowerShell command prompt and type Set-ExecutionPolicy RemoteSigned

      clip_image001

    2. You will be asked if you are sure

      clip_image002

    3. Select ‘Y’ and hit <enter>

      clip_image003

    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”.

    Comments

    51 responses to “How to run ps1 scripts”

    Leave a Reply