Trying to get a list of VMs and their hard disk (vmdk ) sizes and USedspace and provisioned space
get-content vm.txt | % {get-vm $_* | Get-HardDisk | select Parent, Name, CapacityGB } | ft -AutoSize
this works but how do I get the Usedspace and provisoned space as well?
any idea why I am only getting one line in my csv?
PS C:\powershell> get-content vms.txt | %{ get-vm $_* | Get-HardDisk | select PArent, NAme, CapacityGB } | Export-Csv C:\powershell\vm_diskinfo2.csv
At each loop you overwrite the content of the CSV. Try adding -Append to your Export-CSV.
For the guest used space you can find it in (get-vm).Guest.Disks but to do the link with the actual hard disk you need to interact with the guest OS.
Check this post : PowerCLI script to lists Windows Drive letter and VM Disk number in Data center ?
how do I combine
NAme, hard disk 1, hard disk 2, provisionedspacedb and usedspacegb?
when I look at my VM, I see this with get-harddisk
but get-vm shows this for Provisionedspacegb
why isnt it 50gb instead ? where is 54.9 coming from?
ProvisionedSpaceGB is the total of all the used storage space by the VM, not only the HardDisk space.
This number includes the VMX, the swap file, the logs...
You can do something like this, but the Provisioned and Used is only maintained per VM, not per harddisk.
To get the provisioned and used per datastore, you will have to actually look at the files that constitute a harddisk.
Note that the Export-Csv takes the first element in an array to determine how many columns there will be in the CSV, hence the descending sort per number of properties, before the export.
$report = Get-VM | %{
$obj = New-Object PSObject -Property @{
VM = $_.Name
ProvisionedGB = $_.ProvisionedSpaceGB
UsedGB = $_.UsedSpaceGB
}
$i = 1
Get-HardDisk -VM $_ | $%{
$obj | Add-Member -MemberType NoteProperty -Name "HD$($i)" -Value $_.CapacityGB
$i++
}
$obj
}
$report | Sort-Object -Property {($_ | Get-Member -MemberType NoteProperty).Count} -Descending |
Export-Csv report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference