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)}}