How to get disk capacity and free space of remote computer How to get disk capacity and free space of remote computer powershell powershell

How to get disk capacity and free space of remote computer


$disk = Get-WmiObject Win32_LogicalDisk -ComputerName remotecomputer -Filter "DeviceID='C:'" |Select-Object Size,FreeSpace$disk.Size$disk.FreeSpace

To extract the values only and assign them to a variable:

$disk = Get-WmiObject Win32_LogicalDisk -ComputerName remotecomputer -Filter "DeviceID='C:'" |Foreach-Object {$_.Size,$_.FreeSpace}


Much simpler solution:

Get-PSDrive C | Select-Object Used,Free

and for remote computers (needs Powershell Remoting)

Invoke-Command -ComputerName SRV2 {Get-PSDrive C} | Select-Object PSComputerName,Used,Free


Just one command simple sweet and clean but this only works for local disks

Get-PSDrive

enter image description here

You could still use this command on a remote server by doing a Enter-PSSession -Computername ServerName and then run the Get-PSDrive it will pull the data as if you ran it from the server.