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

前端 未结 4 530
一向
一向 2020-12-12 14:23

The Set-ExecutionPolicy command of PowerShell is banned, so I can NOT run like this:

PS> .\\script.ps1 (enter)

Is there another way to r

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-12 15:24

    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.

提交回复
热议问题