尝试执行代码行时出现以下错误
Start-Process : This command cannot be executed due to the error:
Access is denied.
这是正在执行的代码
$username = "domain\username"
$passwordPlainText = "password"
$password = ConvertTo-SecureString "$passwordPlainText" -asplaintext -force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username,$password
$powershellArguments = "D:\path\ps.script.ps1", "arg1", "arg2", "arg3", "arg4"
Start-Process "powershell.exe" -credential $cred -ArgumentList $powershellArguments -wait
-wait
,但无论如何都行不通,并且由于用户享有特权,我宁愿保留它答案 0 :(得分:1)
请看这个链接:
参数“-wait”会抑制命令提示符或保留命令提示符 窗口,直到该过程完成。此操作可能需要 管理员权利。