PoweCLI script to find the VMs with and without RDMs.

Here is the script to generate the list of All VMS, VMs with RDMs and VMs without RDMs in a cluster.

Connect-VIServer xx.xx

$clusters = "Cluster 1", "Cluster 2", "Cluster 4", "Cluster 5"
ForEach($cluster_name in $clusters) {
$vmRDM = @()
$vmFlat = @()
$vmNonRDM = @()

$vmFlat = get-cluster $cluster_name | Get-VM | Get-HardDisk -DiskType "Flat" | Select-Object -Unique Parent | ConvertTo-Csv -NoTypeInformation
$vmFlat = $vmFlat[1..$vmFlat.Length]
$vmFlatCount = "No of VMs : " + $vmFlat.Length
$vmFlatCount | Out-File -FilePath Z:\output\VM-list-$cluster_name.txt
$vmFlat | Out-File -append -FilePath Z:\output\VM-list-$cluster_name.txt
"---------------" | Out-File -append -FilePath Z:\output\VM-list-$cluster_name.txt

$vmRDM = get-cluster $cluster_name | Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select-Object -Unique Parent | ConvertTo-Csv -NoTypeInformation
$vmRDM = $vmRDM[1..$vmRDM.Length]
$vmRDMCount = "No of RDM VMs : " + $vmRDM.Length
$vmRDMCount | Out-File -append -FilePath Z:\output\VM-list-$cluster_name.txt
$vmRDM | Out-File -append -FilePath Z:\output\VM-list-$cluster_name.txt
"---------------" | Out-File -append -FilePath Z:\output\VM-list-$cluster_name.txt

$vmNonRDM = Compare-Object -ReferenceObject $vmRDM -DifferenceObject $vmFlat -PassThru
$vmNonRDMCount = "No of Non-RDM VMs : " + $vmNonRDM.Length
$vmNonRDMCount | Out-File -append -FilePath Z:\output\VM-list-$cluster_name.txt
$vmNonRDM | Out-File -append -FilePath Z:\output\VM-list-$cluster_name.txt

}

-SD