I'm trying install chocolatey using packer.io and powershell script.
I have a two scripts, one for proxy configuration and one for chocolatey install. first script for proxy:
$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
second script for installing chocolatey:
$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'))
I run this scripts using powershell in packer and first script pass, second script doesn't. I get error message:
^[[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
Of course $settings.ProxyServer returns correct proxy address and proxy is enabled. When I run only first script and boot machine created by packer I can manually install chocolatey without any modification and browse internet using IE. If I don't run first script (to set procxy) I won't install anything because of proxy. Also I can't open any internet page. As result I assume that my script for proxy works.
I don't use user and pass for my proxy.
My windows system is Windows 2012 server R2. Packer version 0.10.1
I tried set proxy directly in webclient powershell object but this doesn't work too.
Any ideas?