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:\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 Do I need to do something to make it prompt me for the vm credentials? All the services are running on the vm's