VMware Cloud Community
Shaha
Enthusiast
Enthusiast
Jump to solution

calculating total lunspace freespacemb, capacitymb

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)
Reply
0 Kudos
1 Solution

Accepted Solutions
hugopeeters
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
4 Replies
johnlennon
Enthusiast
Enthusiast
Jump to solution

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

dzi-icoma
Contributor
Contributor
Jump to solution

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
Jump to solution

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

Reply
0 Kudos
hugopeeters
Hot Shot
Hot Shot
Jump to solution

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)

Reply
0 Kudos