1

basically, I get all 0's returned in the percentage1 column. I need help with what I believe is syntax or incorrect use of Round.

Get-Cluster "my_cluster" | Get-VMHost | Get-Datastore | Select Name,@{N="Percentagetest";E={[math]::Round(($_.ExtensionData.Summary.Capacity / $_.ExtensionData.Summary.Freespace)/1GB,3)}}
Tobias
  • 1,236
  • 1
  • 13
  • 25
2legit2quit
  • 171
  • 1
  • 2
  • 10

1 Answers1

1

First, you are missing the underline between the $ and the dot. To access properties of a piped object, you have to use: $_.ExtensionData.Summary.Capacity

Second, i think your calculation is wrong:

  • If you want the percentage of used space, why do you divide through 1GB? THis is only needed if you want to convert the Bytes to GB, but percentage is always between 0 and 100, so no GB convertion is needed.
  • To calculate the percentage, you need a formula like:

FreeSpace_in_percentage = ( freepace / AvailableSpace ) * 100

So your command should look like this, which worked in my environment:

Get-Cluster "my_cluster" | Get-VMHost | Get-Datastore | Select Name,@{N="Percentagetest";E={[math]::Round(($_.ExtensionData.Summary.Freespace/$_.ExtensionData.Summary.Capacity)*100,3)}}
Tobias
  • 1,236
  • 1
  • 13
  • 25
  • actually I did have a $_. i just missed it when i typed it out here...I'll try again though and let you know. thanks Tobias. – 2legit2quit Mar 23 '16 at 21:12