Introduction
Get-VM | Where-Object {
($_ | Get-HardDisk).Count -gt 3
} | Select Name, PowerState, @{N="DiskCount";E={($_ | Get-HardDisk).Count}} | Export-Csv "C:ReportsDiskAudit.csv" -NoTypeInformation
Diagram: Virtual Disk and ISO Cleanup Flow

Step 5: (Optional) Remove Orphaned VMDKs
In this article, you will learn to:
- Identify VMs with multiple virtual disks
- Find disks not attached to a VM (orphaned VMDKs)
- Unmount ISO files from VM CD drives
- Export cleanup candidates to a review CSV
- Perform safe disk and ISO removal operations
Step 1: Find VMs with More Than One Virtual Disk
Get-VM | Where-Object {
($_ | Get-HardDisk).Count -gt 1
} | Select Name, @{N="DiskCount";E={($_ | Get-HardDisk).Count}} | Export-Csv "C:ReportsVMs_Multiple_Disks.csv" -NoTypeInformation
Step 2: Detect Unused or Orphaned VMDK Files
Get-VM | Get-CDDrive | Where-Object {$_.IsoPath -ne $null} | Select Parent, IsoPath
Get-VM | Where-Object {
($_ | Get-HardDisk).Count -gt 1
} | Select Name, @{N="DiskCount";E={($_ | Get-HardDisk).Count}}
Get-Datastore -Name "Datastore1" | Get-ChildItem -Recurse | Where-Object {$_.Name -like "*.vmdk"}
Remove-Item -Path "[Datastore1] VMName/VMName_2.vmdk" -Confirm:$false
Get-VM | Get-CDDrive | Where-Object {$_.IsoPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false
Step 4: Export Potential Cleanup Items
Over time, environments accumulate unused virtual disks and mounted ISOs that consume critical datastore space. Identifying and removing them manually is time-consuming and error-prone. PowerCLI allows you to detect these stale resources and clean them up automatically or in a controlled review process.
Get-Datastore -Name "Datastore1" | Get-ChildItem -Recurse | Where-Object {$_.Name -like "*.vmdk"} | Select Name, DatastoreFullPath, Length
Use Case: Monthly Storage Reclamation Job
- Identify all ISOs still mounted
- Export list of VMs with 3+ disks
- List all VMDK files not attached to powered-on VMs
- Unmount ISOs
- Schedule reports to email storage admins
Troubleshooting
Issue | Solution |
---|---|
CD-ROM remains mounted after script | Use -NoMedia and confirm VMware Tools is working |
Cannot delete VMDK | File may be locked or still attached to an active snapshot |
Get-ChildItem fails on datastore | Ensure datastore browser access is enabled and PowerCLI has permissions |
VMs not reporting IsoPath | Requires up-to-date VMware Tools for guest metadata |