VMware Cloud Community
vmk2014
Expert
Expert
Jump to solution

VMotion is failing and need to check whether the VM's having CD rom mounted or not from Power Cli

Hi Everyone,

One of the ESXi host entered  into maintenance mode and it stuck at 19% but check the VM's edit setting be uase the Tasks is running. Can we see or check from Power Cli if any CD rom mounted or the VM's in local storage?  If yes, can we umount the CD rom from power Cli ?

thanks in advance.

regards,

vmk

Tags (1)
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Yes, you can do

Get-VM | Get-CDDrive | where{$_.IsoPath} |

Set-CDDrive -NoMedia -Confirm:$False

To find the VMs that are on local storage, you could do

Get-VM | where{Get-Datastore -RelatedObject $_ | where {$_.ExtensionData.Info.Vmfs.IsLocal}} |

Select Name


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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

Yes, the CD can be unmounted.

Try like this

Get-VM | Get-CDDrive |

Set-CDDrive -NoMedia -Confirm:$False

Not sure what you mean with the 'local storage' remark.


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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

Can we check first if the CD rom really mounted ? local storage i mean that if the VM is in local storage then it might fail.

PS C:\temp>

PS C:\temp> Get-VM cbv | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False

Set-CDDrive : 12/31/2018 5:14:05 AM     Set-CDDrive             Server task failed: The operation is not allowed in the

current state

of the host.

At line:1 char:40

+ ...  cbv-cscddsview1 | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$False

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

    + CategoryInfo          : NotSpecified: (:) [Set-CDDrive], VimException

    + FullyQualifiedErrorId : Security_Impl_TaskResultConverter_TaskNotSucceeded,VMware.VimAutomation.ViCore.Cmdlets.C

   ommands.VirtualDevice.SetCDDrive

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, you can do

Get-VM | Get-CDDrive | where{$_.IsoPath} |

Set-CDDrive -NoMedia -Confirm:$False

To find the VMs that are on local storage, you could do

Get-VM | where{Get-Datastore -RelatedObject $_ | where {$_.ExtensionData.Info.Vmfs.IsLocal}} |

Select Name


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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

Luckily, i got downtime for the VM's because of Dev & Test and shut down the VM's, hence finally host went to Maintenance mode.

Thanks

vmk

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

Can we get the lists of VM's having CD ROM mounted and ISO image and then based on out we will unmount it ?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can do something like this

Get-VM | where {Get-CDDrive -VM $_ | where {$_.IsoPath}} | Select Name


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

Reply
0 Kudos
vmk2014
Expert
Expert
Jump to solution

LucD,

Can we also pull VM name with ESXi host also, so that before putting the host into maintenance mode we can unmount the CDrom and iso ?

Also, once we identify the VM's names, can we unmount from the lists of VM's ? C:\vmliste.txt

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

This will add the VMHost into the report.

Get-VM | where {Get-CDDrive -VM $_ | where {$_.IsoPath}} |

  Select Name, @{N = 'VMHost'; E = {$_.VMHost.Name}} |

   Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture

And this will use the report, to unmount the ISOs

Import-Csv -Path .\report.csv -UseCulture |

   ForEach-Object -Process {

   Get-VM -Name $_.Name | Get-CDDrive | Set-CDDrive -NoMedia -Confirm:$false

}


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

vmk2014
Expert
Expert
Jump to solution

Thank you LuCD. Before unmounting it, can we determine if the mount is for VMware tools or Windows Installations?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can check the value in IsoPath.
When the VMware Tools ISO is mounted, you should see the VM with this

Get-VM |

   where { Get-CDDrive -VM $_ | where {$_.IsoPath -match '/usr/lib/vmware/isoimages'}} |

  select Name

For Windows ISOs it is similar, but you will have to find the name of the ISO.
That depends on which version and how those ISOs are distributed in your environment.


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