The Set-ExecutionPolicy command of PowerShell is banned, so I can NOT run like this:
PS> .\script.ps1 (enter)
Is there another way to run the PowerShell script except from the "Windows PowerShell ISE"?
PS: I was able to use Java's ProccessBuilder to run a single PowerShell command, but don't know how to run the whole script.
Restricted - No scripts can be run. Windows PowerShell can be used only in interactive mode. AllSigned - Only scripts signed by a trusted publisher can be run. RemoteSigned - Downloaded scripts must be signed by a trusted publisher before they can be run.
This is what we use to run PowerShell scripts from Java (works regardless of the execution policy):
powershell.exe -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden -File <script_name>
The easiest silliest way around this is just:
gc .\script.ps1 | iex
This works in PowerShell and doesn't care about ExecutionPolicy
. Just make sure that you are careful with newlines. Keep {}
s and similar on the same line, using ;
s where needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With