Check Drivespace for Each Drive on a List of Remote Computers

This script Checks a list of remote computers. You specify the servers inside of the $servers variable by placing each in quotes with a comma between entries as I have done below within the script. All you must do then is simply run the script. WMI will discover all drives on the remote machine and give you the total size, used space, free space and percent free. Entries below 15% will be shown in red and all others will be shown in yellow. You can add as many servers as you like, or easily mod the file to read from a text file.

You will probably want to save your credentials with this script as I posted about here for ease of use.

I use this particular script a lot.

#Retrieve Drive Space on Remote Computers

$servers = "Server1", "Server2", "Server3"

$gb = 1024 * 1024 * 1024
foreach ($target in $servers){
write-host "Checking $target..."
$obj = (gwmi -query "select * from win32_logicaldisk where Size > 1" -computername $target -cred $pw)
foreach ($disk in $obj) {
$freespace = ($disk.freespace / $gb)
$totalspace = ($disk.Size / $gb)
$freepercent = (($freespace / $totalspace)*100)
if ($freepercent -lt "15") {
write-host "Drive" ($disk.deviceid) "has" ($disk.freespace / $gb).ToString("n") "GB Free of" ($disk.Size / $gb).ToString("n") "GB." $freepercent.ToString("n") "% Free." -foregroundcolor red
else {
write-host "Drive" ($disk.deviceid) "has" ($disk.freespace / $gb).ToString("n") "GB Free of" ($disk.Size / $gb).ToString("n") "GB." $freepercent.ToString("n") "% Free." -foregroundcolor green