Friday, August 10, 2018

Run Powershell Script on Windows 10

Executing PowerShell script is always easy on Windows but when it comes to Windows 10, it a little bit tricky and need additional attention.

On Windows 10, have different Execution Policies. 

Detailed docs can we found on Microsoft Docs 


The PowerShell script execution policies enable you to determine which Windows PowerShell scripts (if any) will be allowed to run on your computer. Windows PowerShell has four different execution policies:

Execution Policy
Description
Restricted
No PowerShell scripts can be run. Windows PowerShell can be used only in interactive mode. This means that you can only run individual commands. You can't run scripts under this policy, regardless of where the scripts came from (local or downloaded) and whether they are signed.
AllSigned
Only PowerShell scripts signed by a trusted publisher can be run. When you attempt to run a signed script, you'll receive a prompt asking you to confirm that you trust the publisher.
RemoteSigned
Downloaded PowerShell scripts must be signed by a trusted publisher before they can be run. Scripts that you run from the local computer don't need to be signed. There are no prompts when you attempt to run a script.
Unrestricted
No restrictions; all PowerShell scripts can be run.
Undefined(default)
No execution policy has been set.

You can set an execution policy that is effective only in a particular scope.

By default or if you are getting error to execute powershell Sctipt as below then you need to setup execution policy to unrestricted or something like that as per need.

File C:\Scripts\testScript.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170



To Run PowerShell script just select unrestricted scope for current user

Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force -Verbose





No comments:

Post a Comment