简体   繁体   English

如何以编程方式在Azure VM上远程安装.NET 4客户端?

[英]How can I remotely, programmatically install .NET 4 client on an Azure VM?

I am prototyping a build of 2008 R2 on Azure. 我要在Azure上构建2008 R2的原型。 I have working code to deploy the VM, retrieve the x509 certificate, and establish WinRM access to remote Powershell on the deployed VM. 我有工作代码来部署VM,检索x509证书并在部署的VM上建立对远程Powershell的WinRM访问。

I need to install some pre-reqs for our software. 我需要为我们的软件安装一些先决条件。 One of those is .NET 4. When I launch this command: .NET 4就是其中之一。当我启动此命令时:

Invoke-Command -ConnectionUri $azUri -Credential $vmCreds -ScriptBlock {start-process -filepath "c:\\installs\\dotNetFx40_Full_x86_x64.exe" -argumentlist "/q /norestart" -wait}

I get this error in the Setup event log: 我在安装事件日志中收到此错误:

Windows update could not be installed because of error 2147942405 "Access is denied." (Command line: "wusa.exe "C:\\1112ac1e217ef544ae09\\Windows6.1-KB958488-v6001-x64.msu" /quiet /norestart")

The creds I am using are built using the administrative account created with the VM itself. 我使用的凭据是使用VM本身创建的管理帐户构建的。 The file is obtained using FTP via Powershell (I cobbled an FTP function together using .net methods and some googling). 该文件是通过Powershell使用FTP获得的(我使用.net方法和一些谷歌搜索功能将FTP函数拼凑在一起)。

The project I am working on requires that I use one of the clean default images provided by Microsoft, so I can't customize the template ahead of time. 我正在从事的项目要求我使用Microsoft提供的干净的默认图像之一,因此无法提前自定义模板。 Eventually these operations will also be performed by a config management tool such as Chef or Puppet, so I need to be able to do this in a config management style. 最终,这些操作也将由诸如Chef或Puppet之类的配置管理工具执行,因此我需要能够以配置管理样式执行此操作。

I have tried various permutations of this command and this is the closest I've been able to get it to working. 我已经尝试过此命令的各种排列,这是我能够使其执行的最接近的排列。 I disabled UAC and rebooted as an experiment, which did not change the behavior. 我禁用了UAC并重新启动作为实验,但并没有改变行为。 My searching so far has revealed other people having this problem, but no adequate solution that fits my scenario. 到目前为止,我的搜索显示了其他人也有此问题,但没有适合我的情况的适当解决方案。

I've run into this as well and I'm pretty sure the problem is that wusa cannot be invoked remotely: 我也遇到了这个问题,我很确定问题是wusa不能被远程调用:

KB: Windows Update Standalone Installer (WUSA) returns 0x5 ERROR_ACCESS_DENIED when deploying .msu files through WinRM and Windows Remote Shell KB:通过WinRM和Windows Remote Shell部署.msu文件时,Windows Update独立安装程序(WUSA)返回0x5 ERROR_ACCESS_DENIED

The problem stems from the fact that the .NET 4.0 installer has a couple of msu updates that it wants to apply. 问题源于以下事实:.NET 4.0安装程序有几个要应用的msu更新。 Because wusa can't be run from a remote command, the whole shebang fails. 由于无法从远程命令运行wusa,因此整个shebang都会失败。

EDIT: I did some digging and found an undocumented flag in ParamaterInfo.xml - the SkipMSUInstall flag will bypass the msu installs, negating the wusa calls, resulting in a successful install. 编辑:我做了一些挖掘,并在ParamaterInfo.xml中发现了一个未记录的标志-SkipMSUInstall标志将绕过msu安装,否定wusa调用,从而成功完成安装。 I've just run through this on a few hundred servers and it works great. 我刚刚在几百台服务器上运行了它,并且效果很好。 Our security policies don't allow for CredSSP to be used, so I'm copying the install files locally on each server, then using Invoke-Command and Start-Process to run the installs. 我们的安全策略不允许使用CredSSP,因此我要在每个服务器上本地复制安装文件,然后使用Invoke-Command和Start-Process来运行安装。

Modified powershell snippet below: 修改后的Powershell代码段如下:

$servers = get-Content c:\temp\serverlist.txt

foreach ($server in $servers) {
  $session = New-PSSession -ComputerName $server -Credential $credential
  Invoke-Command -session $session -asJob -scriptBlock {
    Start-Process "C:\Temp\dotNetFx40_Full_x86_x64\setup.exe" -ArgumentList "/passive /norestart /SkipMSUInstall" -Wait -Passthru
    }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM