$computerHDDs= Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'"
$logicalDisks = @()
foreach($item in $computerHDDs)
{
$logicalDisk =[ordered]@{
Name=$item.DeviceID -replace ':' ,'';
DiskSize = "{0:N2}" -f ($item.Size/1GB) + " GB" ;
}
$logicalDisks +=$logicalDisk
}
$logicalDisks
Even in psdrive if you are able to get the free and used, then summation of both should give you the total size
In your case, you can do like this:
$hdd= Get-PSDrive C | Select-Object -Property Free,Used
$total= (($hdd.free + $hdd.Used)/1GB).ToString() + " GB"
$total
Note: If you want to get the value only, then remove the tostring method and the GB part. Use the first portion only
And for all drives, you can use like this:
Get-PSDrive -PSProvider filesystem | select Name, @{n= 'Used(GB)' ; e = {"{0:N2}" -f ($_.used/1GB)}}, @{n= 'Free (GB)' ; e = {"{0:N2}" -f ($_.Free/1GB)}}, @{n= 'Total(GB)' ; e = {"{0:N2}" -f (($_.used + $_.Free)/1GB)}} | Format-Table -AutoSize