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.
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
Thanks I'll give it a shot.