List Windows 10 disk space in GB

  • List Windows 10 disk space in GB

    Posted by Roddy Gelberty on 9 July 2020 at 10:29 am

    How can I list Windows 10 disk space in GB? I know the ‘Win32_LogicalDisk‘ wmi class contains that information. But how do I format it in a human readable format.

    Topaz George replied 2 years, 10 months ago 2 Members · 1 Reply
  • 1 Reply
  • Topaz George

    Organizer
    9 July 2020 at 12:01 pm

    $disks = Get-WmiObject -Query "Select * from Win32_LogicalDisk where DriveType=3" -ComputerName $env:COMPUTERNAME -Namespace root\cimv2

    $fList = $disks | ForEach-Object {

    New-Object PSObject -Property @{

    'Name' = $_.DeviceID

    'Space in Total (GB)' = $_.Size / 1GB

    'Free Space in GB' = $_.FreeSpace / 1GB

    'Free Space as a %' = 100 * $_.FreeSpace / $_.Size

    }

    }

    $fList|Format-List