【问题标题】:How to remote uninstall applications with PowerCLI and PowerShell如何使用 PowerCLI 和 PowerShell 远程卸载应用程序
【发布时间】:2021-01-27 23:58:52
【问题描述】:

我创建了这个脚本来从一组虚拟机中远程卸载 VMware 工具。

Get-Module -ListAvailable PowerCLI* | Import-Module

Connect-VIServer -Server 192.168.42.218 -User administrator@vsphere.local -Password mypassword

$GetVm=(Get-VM).where{$_.ExtensionData.Config.GuestFullname -match 'Windows'} | select -expand Name | Out-File -FilePath .\vms.txt

$source = "vms.txt"

$vms = Get-Content -Path $source

foreach ($vmName in $vms) {
$vm = Get-VM -Name $vmName

$app = Get-WmiObject -Query "SELECT * FROM Win32_Product WHERE Name LIKE '%VMware%'"  -ComputerName $vmName


    $app.Uninstall()
    }

我收到如下所示的错误,以防万一我打开所有虚拟机的防火墙但仍然出现此错误。我还可以使用相同的循环启动和关闭远程虚拟机。这是错误:

Get-WmiObject : The RPC server is unavailable.
At C:\work\unins1.ps1:15 char:8
+ $app = Get-WmiObject -Query "SELECT * FROM Win32_Product WHERE Name L ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Get-WmiObject], COMException
+ FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

You cannot call a method on a null-valued expression.
At C:\work\unins1.ps1:18 char:5
+ $app.Uninstall()
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

我需要做些什么来让它提示我输入 vm 凭据吗?所有服务都在虚拟机上运行

【问题讨论】:

    标签: powershell vmware powercli


    【解决方案1】:

    由于您已禁用防火墙,我猜您传递给 Get-WmiObject 的 VM 名称无法由 DNS 解析,这反过来又会导致 RPC 服务器不可用错误。一个简单的检查方法是手动将 VM 的 DNS 名称输入到 Get-WmiObject 行并检查它是否有效。更多信息请看这里:Get-WmiObject : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)

    【讨论】:

      猜你喜欢
      • 2011-03-25
      • 2010-09-11
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 2018-08-11
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      相关资源
      最近更新 更多