【问题标题】:How to run a powershell script or change the session and execute code with different user account?如何运行 powershell 脚本或更改会话并使用不同的用户帐户执行代码?
【发布时间】:2019-10-29 16:51:50
【问题描述】:
我需要使用当前作为系统用户运行的 ec2 userdata 中的域用户帐户运行脚本。
我的代码:
start-Process powershell.exe -Credential $credential -ArgumentList “Start-Process powershell.exe
'C:\Users\test\Desktop\Test\test.ps1' -Verb runAs”
但它正在创建一个可能导致执行错误的弹出窗口
【问题讨论】:
标签:
windows
powershell
amazon-ec2
user-accounts
user-data
【解决方案1】:
只需将 NoNewWindow 开关添加到末尾即可。
start-Process powershell.exe -Credential $credential -ArgumentList “Start-Process powershell.exe 'C:\Users\test\Desktop\Test\test.ps1' -Verb runAs” -NoNewWindow