VMware Cloud Community
dwiggins17141
Contributor
Contributor

Removing VMware Tool Modules via PowerCLI

I have an issue where we need to removed the Network Instrospection modules from serveral thousand VMs but keep File Instrospection module installed. I have found and adapted the following but I'm getting an error. 

 

Script:

Get-VM  | %{

  Mount-Tools -VM $_

  $DriveLetter = Get-WmiObject Win32_CDROMDrive -ComputerName $_.Name | 

    Where-Object {$_.VolumeName -match "VMware Tools"} | Select-Object -ExpandProperty Drive

  $ScriptText = "$DriveLetter\setup64.exe /S /v `"/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs,NetworkIntrospection`""

  Invoke-VMScript -VM $_ -ScriptText $ScriptText -ScriptType bat

}

 

Error:

Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

At line:3 char:18

+ ... $DriveLetter = Get-WmiObject Win32_CDROMDrive -ComputerName $_.Name |

+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException

    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

 

Thanks for any insight is able to provide.

 

Get-VM LWVMUTSET007 | %{
  Mount-Tools -VM $_
  $DriveLetter = Get-WmiObject Win32_CDROMDrive -ComputerName $_.Name | 
    Where-Object {$_.VolumeName -match "VMware Tools"} | Select-Object -ExpandProperty Drive
  $ScriptText = "$DriveLetter\setup64.exe /S /v `"/qn REBOOT=R ADDLOCAL=ALL REMOVE=Hgfs,NetworkIntrospection`""
  Invoke-VMScript -VM $_ -ScriptText $ScriptText -ScriptType bat
}
 
0 Kudos
2 Replies
LucD
Leadership
Leadership

It looks as if you can't do the Get-WmiObject Win32_CDROMDrive remotely.
WHy don't you use Invoke-VMScript to do the Get-WmiObject Win32_CDROMDrive inside the guest OS, return the drive letter, and then do your original Invoke-VMScript.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
dwiggins17141
Contributor
Contributor

Thanks I'll give it a shot.

0 Kudos