Script: Export ALL VMDKs and Associated Information to CSV
# Get data about vmdk and format # Niklas Åkerlund / RTS # source: http://vniklas.djungeln.se/2011/12/05/virtual-machine-vmdk-file-report-with-powercli/
# Connect to vCenter
Connect-VIServer -Server cits-vcenter
# Replace * in line below with portion of VM names if you want a specific subset of VMDKs collected (e.g. VM-Test-*) $VMs = Get-VM -Name * $Data = @()
foreach ($VM in $VMs){ $VMDKs = $VM | get-HardDisk foreach ($VMDK in $VMDKs) { if ($VMDK -ne $null){ $CapacityGB = $VMDK.CapacityKB/1024/1024 $CapacityGB = [int]$CapacityGB $into = New-Object PSObject Add-Member -InputObject $into -MemberType NoteProperty -Name VMname $VM.Name Add-Member -InputObject $into -MemberType NoteProperty -Name Datastore $VMDK.FileName.Split(']')[0].TrimStart('[') Add-Member -InputObject $into -MemberType NoteProperty -Name VMDK $VMDK.FileName.Split(']')[1].TrimStart('[') Add-Member -InputObject $into -MemberType NoteProperty -Name StorageFormat $VMDK.StorageFormat Add-Member -InputObject $into -MemberType NoteProperty -Name CapacityGB $CapacityGB $Data += $into } }
}
# Outputs CSV to path in line below $Data | Sort-Object VMname,Datastore,VMDK | Export-Csv -Path C:\temp\VM-VMDKs.csv -NoTypeInformation











