Set-Execution Policy by Script for LocalMachine - Security Error

Hi, i would like to set the execution policy for scope LocalMachine but i get a Security Error Message. But the policy is changed like it should.

[Installation] :: Error Record:

Message : Sicherheitsfehler
InnerException :

FullyQualifiedErrorId : ExecutionPolicyOverride,Microsoft.PowerShell.Commands.SetExecutionPolicyCo
ScriptStackTrace : bei , C:\Temp\Set-ExecutionPolicy\Deploy-Application.ps1:
Zeile 210
bei , : Zeile 1
bei , : Zeile 1

PositionMessage : In C:\Temp\Set-ExecutionPolicy\Deploy-Application.ps1:210 Zeichen:3
+ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force -Err …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

My command to change the policy is:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force

What is causing the Security Error? Or what better way is change the Policy?

GPO, yes, but i would like to do it over SCCM.


Hi try and use this
Try {Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine -Force}
Catch {}