我想使用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對象中設置代理,但這不起作用。
任何想法?
您是否試過'-ExecutionPolicy unrestricted'?例如像這樣:'@powershell -NoProfile -ExecutionPolicy unrestricted -Command「iex((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))」' –