Shaha
Enthusiast
Enthusiast

calculating total lunspace freespacemb, capacitymb

Jump to solution

Hi,

I'm just discovering the delights of powershell Smiley Happy

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.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
hugopeeters
Hot Shot
Hot Shot

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)

View solution in original post

0 Kudos
4 Replies
johnlennon
Enthusiast
Enthusiast

You can use the Measure-Object cmdlet, it has a sum property.

dzi-icoma
Contributor
Contributor

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

www.powerscripter.net

PowerScripter - customize VI client or VirtualCenter http://powerscripter.net
Shaha
Enthusiast
Enthusiast

sorry being a newbie i'm sure how to use the measure-object cmdlet

0 Kudos
hugopeeters
Hot Shot
Hot Shot

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)

0 Kudos