Hi,
I'm just discovering the delights of powershell
if i have a few LUNS in my environment, i can get the FreeSpaceMB and CapacityMB easily but how do i get a sum of these?
thanks.
Try this:
Get-Datastore | Measure-Object -Property CapacityMB -Sum
Or, if you would like to get really fancy and get it in GB:
[math]::Round(((Get-Datastore | Measure-Object -Property CapacityMB -Sum).Sum / 1024),0)
You can use the Measure-Object cmdlet, it has a sum property.
or you can go like that:
$report = @( )
$sumfree = 0
$sumcap = 0
Get-Datastore | % {
$row = "" | Select-Object Name, FreeSpace, Capacity
$row.Name = $_.Name
$row.FreeSpace = $_.FreeSpaceMB
$row.Capacity = $_.CapacityMB
$sumfree += $_.FreeSpaceMB
$sumcap += $_.CapacityMB
$report += $row
}
$report
Write-Host "Total Free Cap: " $sumfree
Write-Host "Total Cap: " $sumcap
PowerScripter - customize VI client or VirtualCenter to your needs, simplifying administration
sorry being a newbie i'm sure how to use the measure-object cmdlet
Try this:
Get-Datastore | Measure-Object -Property CapacityMB -Sum
Or, if you would like to get really fancy and get it in GB:
[math]::Round(((Get-Datastore | Measure-Object -Property CapacityMB -Sum).Sum / 1024),0)