我有一个启动Powershell脚本的c ++服务应用程序(powershell.exe script.ps1)。在脚本中运行可执行文件但需要使用不同的用户凭据运行。有没有办法在Powershell中使用invoke-expression cmdlet或其他方式执行此操作?
答案 0 :(得分:6)
尝试Start-Process
例如:
Start-Process cmd.exe -arg "/k whoami.exe" -Credential (Get-Credential)
当然,对于您的脚本,您需要以编程方式创建凭据,而不是使用提示输入用户名/密码的Get-Credential
。