我想使用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'))”' –