
Wer das erste Malauf einem Windows 10/11 Client ein Powershellskript ausführen möchte, erhält u.U. diese Fehlermeldung und die Ausführung des Skriptes wird verhindert.
Die Datei "C:\Users\JohnDoe\Documents\ps-script.ps1" kann nicht geladen werden, da die Ausführung von Skripts auf diesem System deaktiviert ist.
Weitere Informationen finden Sie unter "about_Execution_Policies" (https:/go.microsoft.com/fwlink/?LinkID=135170).
+ CategoryInfo : Sicherheitsfehler: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnauthorizedAccess
Die Fehlermeldung sagt eindeutig, dass die Ausführung des Skriptes auf diesem System deaktiviert ist. Also schauen wir mal nach, was denn aktiviert ist bzw. wie der Status der ExecutionPolicy ist, denn so nennt sich dies unter Powershell:
PS C:\WINDOWS\system32> Get-ExecutionPolicy -list
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Undefined
Um nun das Skript ausführbar und auch zukünftige Skripte ausführen zu können, ändere ich die ExecutionPolicy der lokalen Maschine. Optionen sind:
- AllSigned. Requires that all scripts and configuration files are signed by a trusted publisher, including scripts written on the local computer.
- Bypass. Nothing is blocked and there are no warnings or prompts.
- Default. Sets the default execution policy. Restricted for Windows clients or RemoteSigned for Windows servers.
- RemoteSigned. Requires that all scripts and configuration files downloaded from the Internet are signed by a trusted publisher. The default execution policy for Windows server computers.
- Restricted. Doesn’t load configuration files or run scripts. The default execution policy for Windows client computers.
- Undefined. No execution policy is set for the scope. Removes an assigned execution policy from a scope that is not set by a Group Policy. If the execution policy in all scopes is Undefined, the effective execution policy is Restricted.
- Unrestricted. Beginning in PowerShell 6.0, this is the default execution policy for non-Windows computers and can’t be changed. Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the internet, you’re prompted for permission before it runs.
PS C:\WINDOWS\system32> Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope LocalMachine
# oder kürzer
PS C:\WINDOWS\system32> Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Es erflolgt noch eine Abfrage, die ich mit Ja, alle bestätige.

Nun schauen wir uns die Liste der geänderten ExecutionPolicy nochmal an und sehen, dass diese für die lokale Maschine erfolgreich geändert wurde.
PS C:\WINDOWS\system32> Get-ExecutionPolicy -list
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser Undefined
LocalMachine Unrestricted
Thats it … Have Fun!