VMware Cloud Community
GeorgH
Contributor
Contributor
Jump to solution

unmount vmware tools or change CD-Rom settings via PowerCLI

Hi,

My problem:

After upgrading the vmware tools on Redhat Linux Guests the vmware tools remain in the vm properties.

I mean that the vm device: CD-Rom Drive is configured for the Datastore-ISO File [] /vmimages/tools-isoimages/linux.iso

The CD Rom drive is not connected!

I cannot Vmotion such systems.

Is there a way to set the clientcdrom device type  to "clientdevice"  via PowerCLI?

I checked some powercli commands: set-cddrive,  dismount-tools


With the powerclie cmd:

get-vm GuestName | get-cddrive

I'm able to locate the systems who have the problem.

Output:

IsoPath              HostDevice                             RemoteDevice
-------              ----------                             ------------
[] /vmimages/tool...

Via Vsphere Client I'm able to change the config from datastore iso to clientdevice.

and change the mode from emulate ide to pathtrough ide (recommended)

--> A smart solution would be to automate this 2 tasks via powercli.

2 Screenshots:

vmware-tools_cdrom1.jpg

vmware-tools_cdrom2.jpg

Has anyone automated this 2 tasks via powercli

1 Solution

Accepted Solutions
admin
Immortal
Immortal
Jump to solution

Hi Georg,

I think that -NoMedia switch of Set-CDDrive is what you need - it will detach host device or iso file.

Get-VM <filters> | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false

Regards,

Vitali

PowerCLI Team

View solution in original post

12 Replies
LucD
Leadership
Leadership
Jump to solution

Afaik, the vSphere client uses private APIs to mount client device ISOs.

There are no cmdlets nor SDK API methods that do this.


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

0 Kudos
GeorgH
Contributor
Contributor
Jump to solution

Hi LucD,

Could i solve the problem recreating the cdrom?

first Remove-CDDrive

and then New-CDDrive ??

br

George

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That could indeed solve the problem, provided the Remove-CDDrive works while there is still an ISO mounted.


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

0 Kudos
GeorgH
Contributor
Contributor
Jump to solution

Hi LucD,

I tried to remove the cddrive.

get-cddrive -vm GuestVM | remove-cddrive -Confirm:$false
Remove-CDDrive : 03.03.2011 08:49:34    Remove-CDDrive        The VM must be in the following state: PoweredOff.
At line:1 char:48
+ get-cddrive -vm guestVM | remove-cddrive <<<<  -Confirm:$false
    + CategoryInfo          : InvalidOperation: (PoweredOn:PowerState) [Remove-CDDrive], ViError
    + FullyQualifiedErrorId : Common_SharedParameterHelper_VerifyVmIsInState_VmNotInState,VMware.VimAutomation.ViCore.Cmdlets.Commands.RemoveCDDrive

Remove-CDDrive : 03.03.2011 08:49:34    Remove-CDDrive        The VM must be in the following state: PoweredOff.
At line:1 char:48

The vm must be powered off to remove the vm.

Is there a way to remove the cdrom drive from a running vm?

br

Georg

0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi Georg,

I think that -NoMedia switch of Set-CDDrive is what you need - it will detach host device or iso file.

Get-VM <filters> | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false

Regards,

Vitali

PowerCLI Team

GeorgH
Contributor
Contributor
Jump to solution

Hi Vitali,

You solved my problem.

Perfect. Exact what i was searching for!!!!!

!!!! Thank you very much!!!!

br

Georg

0 Kudos
tigerdeccan
Enthusiast
Enthusiast
Jump to solution

looks like this scripts goes through every single vm weather cd mounted or not . hammering the envirnonment.

We need a script which only reconfigure the VMs which have drive mounted .

Get-VM <filters> | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false

0 Kudos
admin
Immortal
Immortal
Jump to solution

Hi,

You're right - the script goes through every single machine. You can filter the result with where cmdlet like this:

Get-VM <filters> | Get-CDDrive | where { $_.IsoPath -or $_.HostDevice -or $_.RemoteDevice } | Set-CDDrive -NoMedia -Confirm:$false

This where statement will filter only those CDDrive objects which are connected in one of the three possible ways.

Hope this helps.

Vitali

0 Kudos
TCPvmadmin
Contributor
Contributor
Jump to solution

Hi,

I read this thread and as I'm wondering there is any way to list all VMs with Emulated IDE on CD-ROM ?

With this option my SDRS cluster can't balance VMs and I need to list all these VMs with this settings.

There is what I did actually to detect it :

$VMs=Get-VM
$resultat=@()
foreach ($x in $VMs) {
if ( (Get-CDDrive $x).ExtensionData.DeviceInfo.Summary -match "Remote") {
$resultat+=$x.name
}
}
$resultat | Out-File C:\scripts\cdrom.txt

Thanks for your help.

0 Kudos
Grzesiekk
Expert
Expert
Jump to solution

Hello.

  yes it is possible:

$a=get-vm name1

$a.extensiondata.config.hardware.device[-2].backing.gettype()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    VirtualCdromRemoteAtapiBackingInfo       VMware.Vim.VirtualDeviceRemoteDeviceBackingInfo

VirtualCdromRemoteAtapiBackingInfo -> this is for emulate

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    VirtualCdromRemotePassthroughBackingInfo VMware.Vim.VirtualDeviceRemoteDeviceBackingInfo

VirtualCdromRemotePassthroughBackingInfo this is for passthrough

I don;t have time now to write you the enumerate script for vms.

idea: get vm, get cdrom dev id, query the .devices by .Key -eq 'id'  and check the backing type and then you can do the rest.

Let me know if this is enough or you want me to write more later.

you can always join channel #powercli on freenode irc network if you want real time help i can help you out during my  breaks if you want Smiley Wink

greg

--- @blog https://grzegorzkulikowski.info
0 Kudos
TCPvmadmin
Contributor
Contributor
Jump to solution

Oh great I will try this ! Thanks !

0 Kudos
gray13
Contributor
Contributor
Jump to solution

This is working...

thanks so much...

i found if there are so many iso mounted it will not auto connected to the server.

get-vm xxxxxx |Get-CDDrive|Where-Object {$_.IsoPath -or $_.HostDevice -or $_.RemoteDevice } |Set-CDDrive -NoMedia -Confirm:$false

0 Kudos