windows - 如何运行 powershell 脚本或更改会话并使用不同的用户帐户执行代码?
问题描述
我需要使用当前作为系统用户运行的 ec2 userdata 中的域用户帐户运行脚本。
我的代码:
start-Process powershell.exe -Credential $credential -ArgumentList “Start-Process powershell.exe
'C:\Users\test\Desktop\Test\test.ps1' -Verb runAs”
但它正在创建一个可能导致执行错误的弹出窗口
解决方案
只需将 NoNewWindow 开关添加到末尾即可。
start-Process powershell.exe -Credential $credential -ArgumentList “Start-Process powershell.exe 'C:\Users\test\Desktop\Test\test.ps1' -Verb runAs” -NoNewWindow
推荐阅读
- css - ReactJS+MaterialUI v1 自动嵌套列表填充
- python - 我们如何在 python 中使用压缩进行日志旋转?
- excel - 我可以使用索引匹配对字符串中的多个文本进行通配符吗
- mongodb - 对数组 mongodb 的索引进行排序
- java - 在服务器上上传 5 个相机图像时,图像在 android 中变得模糊
- json - org.json.JSONException: No value for opening_hours ,如何处理此类错误
- web-services - Talend Studio 运行时
- css - CSS/SCSS 位置:绝对工具提示 - 防止离开屏幕
- java - JSP/Servlet 中的隐藏表单
- postman - 邮递员返回 200ok 而不是 201 created