Virtual Machine VMDK file report with PowerCLI
I have created a simple report-script that gives a list of what kind of format and how many vmdk each VM has. The report tells me if the disks are Thin or Thick and what size they are i GB.
after some magic in Excel it looks like this ๐
And the powerCLI script looks like this, it is quite simple but still gives me information that i need for all my VMs on all datastores and quickly i can tell which machines that uses a lot of disk on my precious SAN ๐
# Get data about vmdk and format # # Niklas ร kerlund / RTS $VMs = Get-VM * $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 } } } $Data | Sort-Object VMname,Datastore,VMDK | Export-Csv -Path C:\temp\VM-VMDKs.csv -NoTypeInformation
Comments
Instead of dividing by 1024/1024 , use 1MB. You can also cast it as an [int] with the same command.
[int]$CapacityGB = $VMDK.CapacityKB/1MB
Lastly, since you are defining all of your properties at once for the custom object, consider using a hashtable of property values
$into=New-Object PSObject -property @{
VMName=$VM.Name
Datastore=$VMDK.FileName.Split(‘]’)[0].TrimStart(‘[‘)
…
}
Sweet! thanks for the input!
Would it be possible to get details of each VM disk on 1 line, instead of separating the details based on disks!
I do not know how to extend dynamically in the object, you can put all VM disk details on a string instead with a foreach loop and that way solve it..
Thanks Niklas, exactly what I needed to detail which specific VMs were located on each datastore.
I know this is an old post, but just wanted to say thanks. I used it this week. It was a great launch pad for me to learn more powershell.
Hi Niklas,
Thanks for great script, i was trying to pull out each datastore NAA ID information but some how its does not work,greatly appreciate if you can provide me some help .
Thank you,
jim
Hi Niklas.
thanks a lot… ๐
excellent script. just wanna figure out if we can display the utilized space as well
Is there a way to get the last modified date of VMDK
Great Script. How would I supply a number of servers supplied in a txt file ?
thanks
SP