Packer.io - 在代理后面安装巧克力

Packer.io - installing chocolatey behind proxy

我正在尝试使用 packer.io 和 powershell 脚本安装 chocolatey。

我有两个脚本,一个用于代理配置,一个用于巧克力安装。 代理的第一个脚本:

$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 returns 正确的代理地址和代理已启用。 当我 运行 只有第一个脚本和由 packer 创建的引导机器时,我可以手动安装 chocolatey,无需任何修改,并使用 IE 浏览互联网。如果我不 运行 第一个脚本(设置 procxy),我不会因为代理安装任何东西。我也无法打开任何网页。结果我假设我的代理脚本有效。

我不使用 user 和 pass 作为我的代理。

我的 windows 系统是 Windows 2012 服务器 R2。 加壳器版本 0.10.1

我尝试直接在 webclient powershell 对象中设置代理,但这也不起作用。

有什么想法吗?

你可以用这个。为我工作。 https://github.com/chocolatey/choco/wiki/Proxy-Settings-for-Chocolatey

显式代理设置

Chocolatey 从 0.9.9.9 开始有明确的代理支持。

您只需配置 1 或 3 个设置,Chocolatey 就会使用代理服务器。 proxy 是必需的,它是代理服务器的位置和端口。 proxyUser 和 proxyPassword 是可选的。 user/password 的值仅在两者都存在时用于凭据。

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

不幸的是,我无法在 Power Shell 中设置代理。如果不手动重新启动 anr 运行 IE [原文如此!]。

,这将不起作用

我在 Autounattend.xml 文件中设置了代理,这个解决方案有效。

在 Windows

上安装 Chocolatey 的两个命令

先决条件:以管理员模式启动 cmd

1) 扩展命令:@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" &&设置 "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

2) 运行 命令:choco install chocolateygui