What I am trying to do is to set -ExecutionPolicy (allow scripts) for the actual process (cmd.exe)
If a write this command in cmd.exe (as Administrator):
PowerShell.exe -ExecutionPolicy Unrestricted
Output is:
Windows PowerShell
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
Lernen Sie das neue plattformübergreifende PowerShell kennen – https://aka.ms/pscore6
Than I put on this command:
PowerShell.exe -Command "SomePowerShellScript.ps"
And all works.
If I try the same from a batch-file, it pauses after the first command.
The reason why I use the first command and not the Powershell specific with Set-ExecutionPolicy is described by Microsoft:
PowerShell.exe -ExecutionPolicy Unrestricted
--> sets ExecutionPolicy to cmd and powershell (script can be started)
PowerShell.exe -Command Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process
--> sets Policy only on actual powershell.exe process (script is not allowed to start)
And for clarifing I don't want to set execution policy to Unrestricted for LocalMachine/CurrentUser if possible.
For explaning this problem, the batch-file is only for "lazy" people to directly start the Powershell-Script without having to set ExecutionPolicy (So it works by double clicking).
Has anyone an idea why the batch-file pauses after the first command (I also tried it with call powershell.exe)?
Thanks for a response :).