windows得新版本系统是不能直接执行ps1脚本的,所以在执行脚本前,需要先更改相关权限。直接执行以下代码就成。
先打开powershell,然后复制粘贴执行完事。
Set-ExecutionPolicy Unrestricted -Force
Set-ExecutionPolicy "RemoteSigned" -Scope Process -Confirm:$false -Force
Set-ExecutionPolicy "RemoteSigned" -Scope CurrentUser -Confirm:$false -Force
如果是powershell脚本的话,可以稍微写个判断,然后执行
$result = get-executionpolicy
if ($result -eq "Restricted")
{
Set-ExecutionPolicy Unrestricted -Force
Set-ExecutionPolicy "RemoteSigned" -Scope Process -Confirm:$false -Force
Set-ExecutionPolicy "RemoteSigned" -Scope CurrentUser -Confirm:$false -Force
}
Get-ExecutionPolicy -List