[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.]
Description:
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.
Usage:
PS C:temp> Check-Diskspace -computer remotepc
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
Drive Name : C:
Total Space : 232.83 GB
Free Space : 0.94 GB
PS C:temp>
Code:
function Check-Diskspace { param ( [parameter(Mandatory = $true)] [string]$computer ) $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 }