Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
379 views
in Technique[技术] by (71.8m points)

java - How do I run a PowerShell script even if Set-ExecutionPolicy is banned?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...