Powershell – Quick Tip #1: Run a .ps1 file

This is an egoistic post, but I need to remember this piece of information, so I’ll put it in a place I’m sure I’ll find it again. I might do that a little more often if my Google searches take too long (or my memory fails more often).

The problem: How do I run a .ps1 file (Powershell script) from within Powershell?

Attempt 1:

PS C:foo> .Install.ps1
File C:fooInstall.ps1 cannot be loaded. The file C:fooInstall.ps1 is
not digitally signed. The script will not execute on the system. Please
see "get-help about_signing" for more details..
At line:1 char:13
+ .Install.ps1 <<<<

Ok, strange but secure. How do you switch it off?

Read here for the details or continue for the summary:

The command “Get-ExecutionPolicy” will return the policy you are currently running with.

There are three options for the execution policy that you can set:

  • AllSigned (default): all scripts need to be signed.
  • RemoteSigned: Only scripts downloaded from the internet must be signed.
  • Unrestricted: Any scripts will run without being signed.

I changed the policy using “Set-ExecutionPolicy RemoteSigned” and voila…

About these ads

4 thoughts on “Powershell – Quick Tip #1: Run a .ps1 file

  1. Yep that’s work, when the ps1 is placed locally, now do you try to execute a ps1 file remotely,

    I have my owner ps1 file and when I try to execute remotely is displayed a Security warning

    Security Warning
    Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your
    computer. Do you want to run \\10.22.68.102\c$\test.ps1?
    [D] Do not run [R] Run once [S] Suspend [?] Help (default is “D”):

    Then this file will be used several times, Do you know how can I avoid this message in order that my ps1 file run any time ?

    Note: the execution policy is REMOTESIGNED, also I tried with UNRESTRICTED but the behavior is the same :(

  2. hmm, sorry i already follow your step but that doesn’t work , i still cannot open my ps1 file, can you give me another solution ? thanks :)

  3. Pingback: powershell, running a ps1 file « My Work Blog

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s