Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 219257

Re: Sum and Average of object properties

$
0
0

Okay great thanks it looks like I'm on the right track. The only question is - I making this report so that it creates a list of virtual machines where each row on the report represents one virtual machine and all of its information. I'm wondering how I would incorporate this such that the bottom two rows contain the average and the total of all of the rows above them. Is there a way to do that?

For example, suppose I modify the report like this:

 

$report = Get-VIEvent -MaxSamples ([int]::MaxValue) -start (Get-Date).AddDays(-9) -finish (Get-Date).adddays(-8) |

Where-Object {"VmCreatedEvent","VmClonedEvent","VmDeployedEvent" -contains $_.Gettype().Name} | %{

    $evtThisNewVMEvent = $_

    Try {

        $vm = Get-VM -Id $_.Vm.VM -ErrorAction Stop

    }

    Catch {

        return

    }

    $vm | Select @{N="VM Name";E={$_.name}},

    @{N="vCPUCount";E={$_.NumCPU}},

    @{N="MemoryGB";E={$_.MemoryGB}},

    @{N="ProvionedSpace-EntireVM-GB";E={[math]::Round(($_.ProvisionedSpaceGB),1)}},

    @{N="UsedSpace-EntireVM-GB";E={[math]::Round(($_.UsedSpaceGB),1)}},

    @{N="FreeSpace-EntireVM-GB";E={[math]::Round(($_.ProvisionedSpaceGB - $_.UsedSpaceGB),1)}},

    @{N="CreatedTime";E={$evtThisNewVMEvent.createdTime}},

} | Sort-Object createdTime |

select vCPUCount, MemoryGB,ProvisionedSpace-EntireVM-GB,UsedSpace-EntireVM-GB,FreeSpace-EntireVM-GB,

CreatedTime,

@{N="TotalRAM";E={%{measure-object-sum-property MemoryGB}}}

 

 

What I am trying to do above is add a property which is the sum of the amount of Memory for each VM.  But I'm trying to make it appear at the bottom of the "MemoryGB" column, as it would in an excel spreadsheet if I had created a cell to total that column.  Is this possible?

As far as actually using the measure-object cmdlet, I'm getting a blank field with the syntax above.  Can the above code be fixed to make the totals appear at the bottom of the corresponding column, and make the measure-object snippet capture the value which now isn't working?  Do I need a hash table for this?


 

 



Viewing all articles
Browse latest Browse all 219257

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>