通过本地系统帐户

时间:2015-11-01 13:07:02

标签: powershell jenkins start-process

我想通过Jenkins Job使用PowerShell部署代码。这在powershell ise中运行良好。

$username = "mydomain\builder"
$password = "notmypassword"
$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))
$Arguments = "-ExecutionPolicy Bypass -File C:\Test.ps1 -NoNewWindow -WorkingDirectory C:\Windows\System32\WindowsPowerShell\v1.0 -NoLogo -NonInteractive"

Start-Process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -Credential $credentials -ArgumentList $Arguments

但是当我从使用本地系统的Jenkins运行它时,我收到以下错误消息。

Start-Process : This command cannot be run due to the error: Access is denied.
At C:\WINDOWS\TEMP\hudson5557889306949142167.ps1:7 char:1
+ Start-Process powershell.exe -Credential $credentials -ArgumentList $

如果更改我将Jenkins服务更改为另一个帐户,它可以正常工作。为什么升级权限不会在本地系统帐户下工作?

注意:test.ps1中唯一的代码是New-Item c:\ scripts \ new_file.txt

1 个答案:

答案 0 :(得分:3)

LocalSystem 下运行脚本时,某些命令似乎有限制。鉴于 LocalSystem

,这在安全性方面是有意义的
  

可以完全无限制地访问本地资源。这也是LocalSystem的缺点,因为LocalSystem服务可以做一些会导致整个系统崩溃的事情。

参考:MSDN, The LocalSystem Account

在SuperUser上有一个类似的问题:Can not create process with elevated permissions from LocalSystem account到目前为止没有答案现在提到这个答案。

TechNet上有一个类似的问题:Runing PowerShell script with the permissions of the LocalSystem user,答案建议通过任务计划程序运行脚本。

我可以考虑将runas/savecred/user:...一起使用,其密码永不过期。 AFAIR您必须以runas交互式调用/savecred一次,输入凭据,然后从下次调用中获取已保存的凭据。

相关问题