繁体   English   中英

如何使用 PowerCLI 和 PowerShell 远程卸载应用程序

[英]How to remote uninstall applications with PowerCLI and PowerShell

我创建了这个脚本来从一组 Vm 中远程卸载 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 凭据吗? 所有服务都在虚拟机上运行

由于您已禁用防火墙,我猜您传递给 Get-WmiObject 的 VM 名称无法由 DNS 解析,这反过来又会导致 RPC 服务器不可用错误。 一个简单的检查方法是将 VM 的 DNS 名称手动输入到 Get-WmiObject 行并检查它是否有效。 有关详细信息,请参阅此处: Get-WmiObject:RPC 服务器不可用。 (来自 HRESULT 的异常:0x800706BA)

暂无
暂无

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

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