2016-07-07 67 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文件中设置了代理,并且此解决方案有效。

相关问题