我不会详细了解为什么需要这些,但用户必须能够将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)