VMware Cloud Community
khaliqamar
Enthusiast
Enthusiast
Jump to solution

sum the value in the colume

This is my query:

Get-Datastore | where{$_.ExtensionData.summary.multiplehostAccess} | where {$_.name -like  "XIO*"}

i am getting this output. can any one guide me how i can sum the value for both FreeSpaceGB and CapacityGB.

pastedImage_0.png

and show them separably, my basic goal is to sum and have percentage of both columes

0 Kudos
1 Solution

Accepted Solutions
kwhornlcs
Enthusiast
Enthusiast
Jump to solution

This should get you started:

$datastores = Get-DataStore|Where {$_.Name -like "XIO*"}

$sumFree = ($datastores| Measure-Object -Property FreeSpaceGB -Sum).Sum

$sumCap = ($datastores| Measure-Object -Property CapacityGB -Sum).Sum

$pctFree = [math]::Round(($SumFree/$sumCap)*100,2)

View solution in original post

0 Kudos
3 Replies
kwhornlcs
Enthusiast
Enthusiast
Jump to solution

This should get you started:

$datastores = Get-DataStore|Where {$_.Name -like "XIO*"}

$sumFree = ($datastores| Measure-Object -Property FreeSpaceGB -Sum).Sum

$sumCap = ($datastores| Measure-Object -Property CapacityGB -Sum).Sum

$pctFree = [math]::Round(($SumFree/$sumCap)*100,2)

0 Kudos
khaliqamar
Enthusiast
Enthusiast
Jump to solution

thank you very much. i am new to programming.

$pctFree = [math]::Round(($SumFree/$sumCap)*100,2)

what is the purpose of ,2 ?

0 Kudos
kwhornlcs
Enthusiast
Enthusiast
Jump to solution

That's how many decimal places the that the resulting percent will be rounded to.

In this case I rounded to two decimal places.