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

查看:88
本文介绍了以另一个用户身份运行 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 = "domainservice.account" 
$pwd1 = "big long huge string of characters"
$pwd = ($pwd1 | ConvertTo-SecureString)
$Credential = New-Object System.Management.Automation.PSCredential $user, $pwd
$args = "\domain.locallocationlocationlocationScriptscript.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天全站免登陆