2016-07-07 53 views
1

我想使用packer.io和powershell腳本安裝巧克力。Packer.io - 在代理後面安裝巧克力

我有兩個腳本,一個用於代理配置,一個用於巧克力安裝。 爲代理的第一個腳本:

$ErrorActionPreference = "Stop" 
# set global proxy 
$reg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" 
Set-ItemProperty -Path $reg -Name ProxyServer -Value "http://mycompoany.proxy:1234" 
Set-ItemProperty -Path $reg -Name ProxyEnable -Value 1 

安裝的巧克力第二個腳本:

$ErrorActionPreference = "Stop" 
$reg = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" 

$settings = Get-ItemProperty -Path $reg 
$settings.ProxyServer 
$settings.ProxyEnable 

iex ((new-object net.webclient).DownloadString('http://chocolatey.org/install.ps1')) 

我運行使用封隔器和一個腳本通過PowerShell中的腳本,第二個腳本沒有。我收到錯誤消息:

^[[0;32m windows-2012-R2-standard: Exception calling "DownloadString" with "1" argument(s): "Unable to connect to^[[0m 
^[[0;32m windows-2012-R2-standard: the remote server"^[[0m 
^[[0;32m windows-2012-R2-standard: At C:\Windows\Temp\script.ps1:19 char:1^[[0m 
^[[0;32m windows-2012-R2-standard: + iex ($wc.DownloadString('https://chocolatey.org/install.ps1'))^[[0m 
^[[0;32m windows-2012-R2-standard: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^[[0m 
^[[0;32m windows-2012-R2-standard: + CategoryInfo   : NotSpecified: (:) [], ParentContainsErrorRecordE^[[0m 
^[[0;32m windows-2012-R2-standard: xception^[[0m 
^[[0;32m windows-2012-R2-standard: + FullyQualifiedErrorId : WebException^[[0m 
^[[0;32m windows-2012-R2-standard:^[[0m 
^[[1;32m==> windows-2012-R2-standard: Deleting output directory...^[[0m 

當然$ settings.ProxyServer返回正確的代理地址並啓用代理服務器。 當我只運行由打包器創建的第一個腳本和啓動機器時,我可以手動安裝chocolatey而無需任何修改,並使用IE瀏覽Internet。如果我不運行第一個腳本(設置procxy),我將不會因爲代理而安裝任何東西。另外我無法打開任何網頁。因此,我認爲我的代理腳本的作品。

我不使用用戶,並通過我的代理。

我的Windows系統是Windows 2012服務器R2。 Packer版本0.10.1

我試着直接在webclient的PowerShell對象中設置代理,但這不起作用。

任何想法?

+0

您是否試過'-ExecutionPolicy unrestricted'?例如像這樣:'@powershell -NoProfile -ExecutionPolicy unrestricted -Command「iex((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))」' –

回答

0

您可以使用它。爲我工作。 https://github.com/chocolatey/choco/wiki/Proxy-Settings-for-Chocolatey

設定代理服務器

的巧克力有明確的代理支持開始0.9.9.9。

您可以簡單地配置1或3個設置,而Chocolatey將使用代理服務器。代理是必需的,並且是代理服務器的位置和端口。 proxyUser和proxyPassword是可選的。用戶/密碼的值僅在兩者都存在時才用於憑據。

choco config set proxy <locationandport> 
choco config set proxyUser <username> 
choco config set proxyPassword <passwordThatGetsEncryptedInFile> 

運行在0.9.9.9以下命令:

choco config set proxy http://localhost:8888 
choco config set proxyUser bob 
choco config set proxyPassword 123Sup#rSecur3 
0

可惜的是我不能在電源外殼設置代理。如果沒有重新啓動並且手動運行IE一次[sic!],這不起作用。

我在Autounattend.xml文件中設置了代理,並且此解決方案有效。