≡ Menu

Powershell function to Check disk free space on remote computers

[PLEASE USE https://techibee.com/powershell/check-disk-space-of-remote-machine-using-powershell/430 to check free disk space of remote computer. I made it more advanced there.]


This function takes the computer name as argument and displays the disk free/total size information. One advantage with this function is, no need to search for admin windows when you want to run it. It prompts for admin credentials and connects to remote computer using them.


PS C:temp> Check-Diskspace -computer remotepc
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Drive Name :  C:

Total Space :  232.83 GB

Free Space :  0.94 GB

PS C:temp>


function Check-Diskspace {            
param (            
[parameter(Mandatory = $true)]             
$cred = Get-Credential            
$drives = Get-WMIObject -Class Win32_LogicalDisk -ComputerName $computer -Credential $cred | where { $_.DriveType -eq 3 }            
foreach ($drive in $drives) {            
write-host "Drive Name : " $drive.DeviceID             
write-host "Total Space : "($drive.size/1GB).ToString("0.00") "GB"             
write-host "Free Space : " ($drive.FreeSpace/1GB).ToString("0.00") "GB"             
write-host " "            
$cred = $null            

Comments on this entry are closed.

  • Aravind October 15, 2014, 5:43 pm

    Please tell me how to get folder size which is present on remote windows server
    for example: I want to know size of folder (D:\myfolder) present on xyz windows server.Please let me knoe how can it be achieved

  • Sitaram Pamarthi October 18, 2014, 7:46 pm


    Try this article. The -Name parameter should be ‘\\XYZ\d$\myfolder’

  • Conroy July 9, 2015, 11:19 pm

    You should remove the blocks in your code. It will break PowerShell

    • TechiBee July 10, 2015, 7:16 am

      Thanks for highlighting it. Feedback like this will improve the usability of this blog.

      I have updated the code to fix the unexpected characters that were added by syntax highlighter(a plug-in I used earlier).