Powershell -sum and then output totals

Soldato
Joined
8 Mar 2005
Posts
3,615
Location
London, UK
I am trying to pull together some license consumption statistics where there are multiple license entries for each license type which need to be summed.

First part gives me:
Code:
$usagetot = ($licensePool | where-object {$_.License -like "License Type"} | measure Count ,InUseCount, PooledAvailable,Overdraft -sum)

Outputs ...

Count    : 2
Average  :
Sum      : 925
Maximum  :
Minimum  :
Property : Count

Count    : 2
Average  :
Sum      : 560
Maximum  :
Minimum  :
Property : InUseCount

Count    : 2
Average  :
Sum      : 365
Maximum  :
Minimum  :
Property : PooledAvailable

Count    : 2
Average  :
Sum      : 0
Maximum  :
Minimum  :
Property : Overdraft

However, I'm struggling to then call each properties sum separately from this array.

Ultimately I'm trying to get it into a format recongised by the rrdtool e.g.

Code:
$unixtime = [int][double]::Parse($(Get-date -date (Get-Date).ToUniversalTime()-uformat %s))

Something then like -
$cmd = " rrdtool update rrdtooldb $($unixtime):$($usagetot.Count.sum):$($usagetot.InUseCount.sum):$($usagetot.PooledAvailable.sum):$($usagetot.Overdraft.sum)"
which would then output like ...
rrdtool update rrdtooldb 1530260250:925:560:365:0
I'm almost there ...

Cheers, Paul.
 
Associate
Joined
2 Jul 2003
Posts
2,436
Try these?
($usagetot | Where {$_.Property -Eq "Count"}).Sum
($usagetot | Where {$_.Property -Eq "InUseCount"}).Sum
($usagetot | Where {$_.Property -Eq "PooledAvailable"}).Sum
($usagetot | Where {$_.Property -Eq "Overdraft"}).Sum

or if they're always at the same index of the array
$usagetot[0].Sum
$usagetot[1].Sum
$usagetot[2].Sum
$usagetot[3].Sum
 
Soldato
OP
Joined
8 Mar 2005
Posts
3,615
Location
London, UK
Try these?
($usagetot | Where {$_.Property -Eq "Count"}).Sum
($usagetot | Where {$_.Property -Eq "InUseCount"}).Sum
($usagetot | Where {$_.Property -Eq "PooledAvailable"}).Sum
($usagetot | Where {$_.Property -Eq "Overdraft"}).Sum

or if they're always at the same index of the array
$usagetot[0].Sum
$usagetot[1].Sum
$usagetot[2].Sum
$usagetot[3].Sum
Thank you!

Powershell really does blind-side me with its simplicity!
 
Back
Top Bottom