ExecutionPolicy Bypass无法正常工作

时间:2018-02-08 10:12:49

标签: powershell executionpolicy

$Adminusername = 'domain\blah'
$password = 'blah'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $Adminusername, $securePassword
$path = "\\blah\script.ps1"

Start-Process powershell -ArgumentList "-noexit", "-file $path", "-command &{Set-ExecutionPolicy Bypass}", "-username $username", "-roamingprofilepath $RoamingProfilePath", "-localappdatapath $localappdatapath" -credential $Credential

上面的脚本是一个PowerShell进程,它启动第二个PowerShell,但以另一个用户身份运行它。第一个PowerShell会话的参数将传递给第二个参数。

它工作正常,但在第二个PowerShell进程中,执行策略不会绕过,它会一直提示您允许脚本运行。我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

这对我有用

Start-Process powershell.exe -ArgumentList "/noexit", "-executionpolicy bypass","-file \\server\share\test.ps1"