Friday, May 17, 2013

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


Problem:

PS C:> C:\Test.ps1

File C:\Test.ps1 cannot be loaded. The file C:\Test.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 + .Test.ps1 <<<<


Solution:

Run the below command

PS C:\> Get-ExecutionPolicy
Restricted

It will return the policy you are currently running with. (For ex: Restricted)

Actually, 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 have changed the my policy using the below command like RemoteSigned


PS C:\> Set-ExecutionPolicy RemoteSigned

Then I have run the below Get-ExecutionPolicy command and I got ByPass

PS C:\> Get-ExecutionPolicy
ByPass

Finally, I can able to run the Test.ps1 file successfully.




No comments:

Post a Comment