Montag, 19. Februar 2018

PowerShell script cannot be loaded due to policy settings

Problem

You have a PowerShell script that does not run and trying to do so calling it from command line or bat script it gives you something like below meaning what is described in the title.
Die Datei "C:\Users\kellnert\Documents\bin\svn_updates.ps1" kann nicht geladen werden, da die Ausführung von Skripts
auf diesem System deaktiviert ist. Weitere Informationen finden Sie unter "about_Execution_Policies" unter
"http://go.microsoft.com/fwlink/?LinkID=135170".
    + CategoryInfo          : Sicherheitsfehler: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnauthorizedAccess

Solution

Call PowerShell with following option.
-ExecutionPolicy RemoteSigned
It makes Windows require only remote PowerShell scripts being signed. What a nonsense invention of M$ if it so easily wrapped away. The total call could look like below.
powershell -ExecutionPolicy RemoteSigned -File "%~dp0%~n0.ps1"