VMware Cloud Community
pt073
Contributor
Contributor
Jump to solution

Get-Datastore in GB looking for help with decimal.

Hello,

Any help would be appreciated.

I'm running the get-datastore in GB and looking to return the number without trailing decimal places.

Get-datastore | select name,@{ Label = "FreespaceGB"; Expression = { $_.FreeSpaceMB * 1MB / 1GB }} ,@{ Label = "CapacityGB"; Expression = { $_.CapacityMB * 1MB / 1GB } }

It returns this:

"local-Test01","91.1962890625","131.75"

I would like to have it where it gives me round numbers lik "91", "131"

Thanks!

0 Kudos
1 Solution

Accepted Solutions
mattboren
Expert
Expert
Jump to solution

Hello, pt073-

You can use the Round() method of the .Net "Math" class to round to zero (0) decimal places, like:

Get-Datastore | Select name,@{ Label = "FreespaceGB"; Expression = { [Math]::Round($_.FreeSpaceMB * 1MB / 1GB, 0) }}, @{ Label = "CapacityGB"; Expression = { [Math]::Round($_.CapacityMB * 1MB / 1GB, 0) }}

Btw, you could shorten it up a bit like:

Get-Datastore | Select name,@{l="FreespaceGB"; e={[Math]::Round($_.FreeSpaceMB / 1kb, 0)}}, @{l="CapacityGB"; e={[Math]::Round($_.CapacityMB / 1kb, 0)}}

Just a touch cleaner (used a couple of abbreviations, and consolidated the arithmetic), but, yours works just fine, too (w/ the Round() added).

Enjoy.

View solution in original post

0 Kudos
2 Replies
mattboren
Expert
Expert
Jump to solution

Hello, pt073-

You can use the Round() method of the .Net "Math" class to round to zero (0) decimal places, like:

Get-Datastore | Select name,@{ Label = "FreespaceGB"; Expression = { [Math]::Round($_.FreeSpaceMB * 1MB / 1GB, 0) }}, @{ Label = "CapacityGB"; Expression = { [Math]::Round($_.CapacityMB * 1MB / 1GB, 0) }}

Btw, you could shorten it up a bit like:

Get-Datastore | Select name,@{l="FreespaceGB"; e={[Math]::Round($_.FreeSpaceMB / 1kb, 0)}}, @{l="CapacityGB"; e={[Math]::Round($_.CapacityMB / 1kb, 0)}}

Just a touch cleaner (used a couple of abbreviations, and consolidated the arithmetic), but, yours works just fine, too (w/ the Round() added).

Enjoy.

0 Kudos
pt073
Contributor
Contributor
Jump to solution

Excellent Thank You !  Smiley Happy

0 Kudos