2015-11-01 148 views
4

我想通過Jenkins Job使用PowerShell部署代碼。這在powershell ise中工作正常。通過本地系統帳戶通過PowerShell提升信用度

$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唯一的代碼是新建項目C:\腳本\ new_file.txt

回答

2

似乎當腳本下本地系統運行是對某些命令的限制。這使得在安全方面的意義,因爲本地系統

對本地資源具有完全不受限制的訪問。這也是LocalSystem的缺點,因爲LocalSystem服務可以執行可能會降低整個系統的功能。

參考:MSDN, The LocalSystem Account

有一個在超級用戶類似的問題: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一次,輸入憑證,並將從下一次調用開始保存憑證。

+0

要保存憑據我打開命令提示符作爲本地系統這樣 'PSEXEC -i -s cmd.exe' 你需要右鍵點擊PSEXEC並勾選以管理員身份運行這個工作。 然後我第一次運行我的powershell腳本。 我被提示輸入密碼,然後我得到了Acces Denied! 最後我改變了詹金斯帳戶使用別的東西。然而,這裏有一個解決方案,我沒有嘗試 [鏈接](http://www.brandonmartinez.com/2013/04/24/resolve-access-is-denied-using-psexec-with-a-local-管理員帳戶) –

相關問題