以其他用户身份运行PowerShell,并启动脚本 [英] Running PowerShell as another user, and launching a script

查看:677
本文介绍了以其他用户身份运行PowerShell,并启动脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不会详细说明为什么需要这样做的所有细节,但是用户必须能够将PowerShell作为服务帐户启动,并且在PowerShell加载时需要运行脚本.我已经可以使用存储的凭据(存储为安全字符串)启动PowerShell,但是我一生都无法运行脚本(位于$ args中).我已经尝试了多种方法,下面是我目前所在的位置.任何帮助将不胜感激.

I won't get into all the details of why I need this, but users must be able to launch PowerShell as a service account and when PowerShell loads it needs to run a script. I already can launch PowerShell with the stored credentials (stored as a secure string), but for the life of me I cannot get the script (located in $args) to run. I have tried a variety of things, and below is where I am currently. Any help would be greatly appreciated.

$user = "domain\service.account" 
$pwd1 = "big long huge string of characters"
$pwd = ($pwd1 | ConvertTo-SecureString)
$Credential = New-Object System.Management.Automation.PSCredential $user, $pwd
$args = "\\domain.local\location\location\location\Script\script.ps1"
Start-Process powershell.exe -Credential $Credential -ArgumentList ("-file $args")

推荐答案

您可以在指定的用户凭据下打开一个新的powershell窗口,如下所示:

You can open a new powershell window under a specified user credential like this:

start powershell -credential ""

这篇关于以其他用户身份运行PowerShell,并启动脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆