how can I sum up the total vmdk sizes (not thin) of a list of vms from vc?
Hello, again-
I see your second post. Yes, you could go that route, too. You are almost there, just need to add in a Measure-Object call. A bit cleaned up, it would be like:
$machines = Get-Content c:\servers.txt
Get-VM -Name $machines | Get-HardDisk | `
select @{N="VMName";E={$_.Parent.Name}},@{N="Capacity(GB)";E={[math]::truncate($_.CapacityKB / 1MB)}},Filename | `
Measure-Object -Property "Capacity(GB)" -Sum
How does that do for you?
came up somehting like this. could be better
I want to get a sum of the total usage of all vms.
Hello, tdubb123-
There are several ways that you could get the sum of the sizes of the given VMs' disks. One such way would be like:
## get the total GB of given VMs' disks
## if certain that all disks are thick
$arrVMNamesToCheck = Get-Content c:\temp\VMNames.txt
$($arrVMNamesToCheck | %{Get-View -ViewType VirtualMachine -Property Name, Config.Hardware.Device -Filter @{"Name" = $_}} | %{
$_.Config.Hardware.Device | ?{$_ -is [VMware.Vim.VirtualDisk]} | %{$_.CapacityInKB / 1MB}
} | Measure-Object -Sum).Sum
Enjoy
Hello, again-
I see your second post. Yes, you could go that route, too. You are almost there, just need to add in a Measure-Object call. A bit cleaned up, it would be like:
$machines = Get-Content c:\servers.txt
Get-VM -Name $machines | Get-HardDisk | `
select @{N="VMName";E={$_.Parent.Name}},@{N="Capacity(GB)";E={[math]::truncate($_.CapacityKB / 1MB)}},Filename | `
Measure-Object -Property "Capacity(GB)" -Sum
How does that do for you?
hi mattboren,
yes this works great. for my second post. how do I have
select @{N="VMName";E={$_.Parent.Name}},@{N="Capacity(GB)"
show up just once and everything under it. I gues I have to move this out of the loop
thanks
Hello-
It sounds like you are saying that you just want the Format-Table to happen once, instead of for each VM. Makes sense. You could do so with the first example below by basically moving the Format-Table outside of the foreach loop. But, really, you do not need a foreach loop here, since Get-VM will take an array of VM names as a value for the -Name parameter.
You can just pass the entire array of VM names to one Get-VM call, and continue on with the pipeline. See the second example for how that looks (both assume you have already created the $machines array with the Get-Content line).
first way:
## using a foreach loop, passing one VM name at a time to Get-VM
&{foreach ($machine in $machines) {
Get-VM -Name $machine | Get-HardDisk | `
select @{N="VM Name";E={$_.Parent.Name}},@{N="Capacity(GB)";E={[math]::truncate($_.CapacityKB / 1MB)}},Filename
}} | ft -AutoSize
second (probably better, definitely cleaner) way:
## passing all VM names at the same time to Get-VM (passing the array/collection)
Get-VM -Name $machines | Get-HardDisk | `
select @{N="VM Name";E={$_.Parent.Name}},@{N="Capacity(GB)";E={[math]::truncate($_.CapacityKB / 1MB)}},Filename |
ft -AutoSize
Work out ok for you?