$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进程中,执行策略不会绕过,它会一直提示你允许脚本运行。我在这里做错了什么?
发布于 2018-02-08 19:51:49
这对我很管用
Start-Process powershell.exe -ArgumentList "/noexit", "-executionpolicy bypass","-file \\server\share\test.ps1"https://stackoverflow.com/questions/48682883
复制相似问题