I got this far : Get-VM -Location <foldername> | foreach {Get-HardDisk -VM $_.name} | Measure-Object CapacityGB -Sum
This outputs the total size of all diskspace used by the VMs into the specified folder.
I would like to extend this and come to a report/table view below:
Foldername
VM1 used diskspace
VM2 used diskspace
VM3 used diskspace
Total size of all diskspace used all VM in this folder
Is this possible ?
Anyone having some tips and hints to point me in the right direction ?
Thanks a lot !
I don't think you need the sum. I am a bit unclear what you are looking to capture.
try running this:
get-folder <foldername> | get-vm | foreach {Get-HardDisk -VM $_.name}
For me, this lists each of the vm's
CapacityGB Persistence Filename (which includes path)
You could always pipe this into a .csv and manipulate to your preferences.
Thanks for your reply.
I really need the 'sum' of all used diskspace of all VMs / folder.
A more simple view would also work for me, being:
<Foldername> <UsedDiskSpace (which is sum of all used diskspace by the VMs in this folder)>
Gotcha
Not quite sure I have your format yet....
get-folder <foldername> | get-vm | foreach {Get-HardDisk -VM $_.name} | Measure-Object CapacityGB -Sum
Is getting closer(items returned) :
Count
Average
Sum
MAx
Min
Property
Is folder what you are actually looking for? Sometimes I find that "folder" is not what you think it means with vmware. You might be able to get what you are looking for a bit easier with different items such as datastore. Sorry, I am just trying to understand your question better.
I really need the sum per folder (VM Templates and Folders). These folders are used by our backup software and want to spread the Diskusage per folder as much as possible.
How about this?
Get-Folder | foreach {Get-VM | foreach {Get-HardDisk -VM $_.name} | Measure-Object CapacityGB -sum}
See if this works better:
$folders = get-folder
$mydata = foreach($folder in $folders({
$folder.name
get-folder $folder.name | get-vm | foreach {get-harddisk -VM $_.name} | Measure-Object CapacityGB -sum
}
$mydata
Thanks jpsider.
With your hints I finally created below and created a 'new object' which gives me the flexibility to output the data in multiple output formats.
$folders = get-folder
foreach($folder in $folders){
$SumFolder = get-folder $folder.name | get-vm | foreach {get-harddisk -VM $_.name} | Measure-Object CapacityGB -sum
$obj = New-Object -TypeName PSObject
$obj | Add-Member -MemberType NoteProperty -Name "Folder Name" -Value $folder.name
$obj | Add-Member -MemberType NoteProperty -Name "Capacity in GB" -Value $SumFolder.Sum
$Finalobj = [Array]$Finalobj + $obj
}
Thanks for the help !