[英]Why does invoke operator (&) and Invoke-Expression produce different results for the same input?
[英]How to user Powershell 'invoke-expression' to run an executable as a different user
我有一个启动Powershell脚本的c ++服务应用程序(powershell.exe script.ps1)。 在脚本中运行可执行文件但需要使用不同的用户凭据运行。 有没有办法在Powershell中使用invoke-expression cmdlet或其他方式执行此操作?
尝试Start-Process
例如:
Start-Process cmd.exe -arg "/k whoami.exe" -Credential (Get-Credential)
当然,对于您的脚本,您需要以编程方式创建凭据,而不是使用提示输入用户名/密码的Get-Credential
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.