Powershell function to Check disk free space on remote computers
filed in PowerShell on Jul.29, 2010
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 = gwmi -class Win32_LogicalDisk -computer $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
}



