PowerCLI List all VMDK disks and what datastore they are on

Once an a while I need to list all my vmdk’s and what datastore they are on… So I created this script with output to CSV:

$outputFile = "D:\tmp\output.csv" 

$VMsAdv = Get-VM | Sort-Object Name | % { Get-View $_.ID } 
$myCol = @() 
ForEach ($VMAdv in $VMsAdv) 
    ForEach ($Disk in $VMAdv.Layout.Disk) 
        $myObj = "" | Select-Object Name, Disk 
        $myObj.Name = $VMAdv.Name 
        $myObj.Disk = $Disk.DiskFile[0] 
        $myCol += $myObj 
$myCol | Export-Csv $outputFile -NoTypeInformation


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.