I created this script to remotely uninstall VMware tools from a group of Vm's.
Get-Module -ListAvailable PowerCLI* | Import-Module
Connect-VIServer -Server 192.168.42.218 -User [email protected] -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()
}
I get the error shown below just in case I turned the firewall of on all vm's but still got this error. I'm also enable to start and shutdown the remote Vm's with the same loop. Here is the error:
Get-WmiObject : The RPC server is unavailable.
At C:workunins1.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:workunins1.ps1:18 char:5
+ $app.Uninstall()
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Do I need to do something to make it prompt me for the vm credentials? All the services are running on the vm's
question from:
https://stackoverflow.com/questions/65929167/how-to-remote-uninstall-applications-with-powercli-and-powershell 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…