powershell预备知识
Get-ExecutionPolicy
Set-ExecutionPolicy Unrestricted
write-host “Hello world!”
1 powershell执行ps文件
策略不能是Restricted
.\test.ps1
2 cmd命令行执行ps文件
如果是在cmd下,需要在命令前面加powershell
powershell -file test.ps1
powershell ./test.ps1
其中powershell test.ps1c出错
3 策略开启
Unrestricted 权限最高,可以不受限制执行任意脚本
Restricted 默认策略,不允许任意脚本的执行
AllSigned 所有脚本必须经过签名运行
RemoteSigned 本地脚本无限制,但是对来自网络的脚本必须经过签名
Bypass 没有任何限制和提示
Undefined 没有设置脚本的策略
Get-ExecutionPolicy
Set-ExecutionPolicy Unrestricted
如果设置权限为Unrestricted,需要管理员启动powershell
非管理员启动情况,有提示