I used the following PowerShell script, try it:
# Prompt for credentials
$vcServer = "vcenter.yourdomain.local"
$vcUser = "username"
$vcPass = Read-Host -Prompt "Enter password for $vcUser" -AsSecureString
# Connect to vCenter
Connect-VIServer -Server $vcServer -User $vcUser -Password $vcPass
# Path to VM list text file (one VM name per line)
$vmListPath = "C:\Path\To\VMlist.txt"
# Remove CD/Drive1 from each VM in the list
Get-Content $vmListPath | ForEach-Object {
$vmName = $_.Trim()
if ($vmName) {
$cdDrive = Get-VM -Name $vmName | Get-CDDrive
if ($cdDrive) {
Remove-CDDrive -CDDrive $cdDrive -Confirm:$false
Write-Host "Removed CD/Drive from VM: $vmName"
} else {
Write-Host "No CD drive found for VM: $vmName" -ForegroundColor Yellow
}
}
}
# Disconnect from vCenter
Disconnect-VIServer -Server $vcServer -Confirm:$false
-------------------------------------------
Original Message:
Sent: Aug 11, 2025 03:31 PM
From: Jose Castro
Subject: VMList to delete the "CD/Drive1" from VMs
Hello All! I am a novice Powershell guy. Looking for efficient way to delete the "CD/Drive1" from a list of VMs.
I have a command below that removes a mounted ISO so just looking for the equivilant to delete the drive entirely
get-vm | get-CDDrive | Where {$_.IsoPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false.
Just looking for help around leverating the text file w/ the VMnames and this command equivilant to removal of the CD/Drive1 entirely. Thanks!
-------------------------------------------