[Original] Use PowerShell script to uninstall the CD of the virtual machine in ESXI

When the virtual machine data is migrated, sometimes the virtual machine still has an ISO disc attached, but the storage device still shows that the virtual machine is using this storage.

Here, as long as the mounted CD of the virtual machine is removed, the virtual machine will not be associated with the storage, and the storage will not display the virtual machine to use it again.

If you manually click on the virtual machines one by one to set them up, it will take too much time. You can consider using scripts to complete them. Just execute the following script.

#导入PowerCLi包
Import-Module VMware.VimAutomation.Core
#连接vCenter服务器
Connect-VIServer -Server 192.168.0.10 -Protocol https -User [email protected] -Password MyPassWord
#检查存储
Get-Datastore
#获取某存储上的虚拟机列表
Get-VM -Datastore ZR01
#获取 TEST_WIN10_2 信息
Get-VM -Name TEST_WIN10_2
# 获取 TEST_WIN10_2 的光驱信息
Get-VM -Name TEST_WIN10_2 | Get-CDDrive
# 设置 TEST_WIN10_2 的光驱信息
Get-VM -Name TEST_WIN10_2 | Get-CDDrive | Set-CDDrive  -NoMedia -Confirm:$false
#现在 TEST_WIN10_2 的光驱中光盘被卸掉了。

Processing one by one is too slow, so let's process in batches.

Get-VM -Datastore ZR01 | Get-CDDrive | Set-CDDrive  -NoMedia -Confirm:$false

Guess you like

Origin blog.csdn.net/u013667796/article/details/130655820