我不会详细了解为什么需要这些,但用户必须能够将PowerShell作为服务帐户启动,并且当PowerShell加载时,它需要运行脚本.我已经可以使用存储的凭据(存储为安全字符串)启动PowerShell,但在我的生活中,我无法运行脚本(位于$ args中).我尝试过各种各样的东西,下面是我目前所处的位置.任何帮助将不胜感激.
$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")
Run Code Online (Sandbox Code Playgroud)
Geo*_*ton 50
您可以在指定的用户凭据下打开一个新的PowerShell窗口,如下所示:
start powershell -credential ""
Run Code Online (Sandbox Code Playgroud)
Duk*_*ets 34
我发现这对我有用.
$username = 'user'
$password = 'password'
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $username, $securePassword
Start-Process Notepad.exe -Credential $credential
Run Code Online (Sandbox Code Playgroud)
更新:更改为使用单引号以避免Paddy注意到的特殊字符问题.
Sem*_*bov 31
这也是通过UI实现这一目标的好方法.
0)在任务栏上右键单击PowerShell图标
1)Shift +右键单击Windows PowerShell
2)"以不同的用户身份运行"
尝试将RunAs选项添加到您的Start-Process
Start-Process powershell.exe -Credential $Credential -Verb RunAs -ArgumentList ("-file $args")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
215300 次 |
| 最近记录: |