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!
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.
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.
Excellent Thank You !