The default permission level for Windows PowerShell is Restricted, which does not allow the execution of PS scripts (that is,. ps1 files). If you run under the Restricted permission level, you get an error message:
|
. \xxxx.ps1:file XXXX.PS1 cannot be loaded because running scripts are disabled on the this system. For more information, see about_execution_policies at http://go.microsoft.com/fwlink/?LinkID=135170. At Line:1 char:1 +. \xxxx.ps1 params[] ... + ~~~~~~~~~~~~~~~~~~~~ + Categoryinfo:securityerror: (:) [], Pssecurityexception + fullyqualifiederrorid:unauthorizedaccess |
To resolve such problems, it is common practice to start the PS command line with administrator privileges and modify the execution permissions to remotesigned or unrestricted:
Set-executionpolicy remotesigned
Here, it is generally possible to solve the problem in most cases.
However, sometimes it is found that some PS script will still throw the above error. If your system is a 64-bit Windows, then it is possible that you execute scripts that are called Powershell.exe not the one you have changed permissions for. Run PowerShell from the following two locations and view the permission settings:
- C:\Windows\System32\WindowsPowerShell\v1.0
- C:\Windows\SystemWoW64\WindowsPowerShell\v1.0
Get-executionpolicy
If there is a restricted change it to remotesigned or unrestricted.
Reference: Https://social.technet.microsoft.com/Forums/en-US/3bd44cf2-684c-4c10-9102-26f2a7b7741d/cant-run-scripts? Forum=winserverpowershell
Pssecurityexception PowerShell permission settings