Check Free Hard Disk Space with Powershell

What about knowing the freespace of every hard disk on every computer in your network ? Try this :

##############################################
#
# Desc : Check FreeSpace on every Computer’s HardDisk

##############################################

$HardDisk_Type = “3”
$OutputFileName = “C:\OutputFile.txt”
$InputFileName = “C:\ServerList.txt”
$Credencial = Get-Credential
$Machines = Get-Content $InputFileName
Foreach ($HostName in $Machines)
{ $T=$null
$T= Get-WmiObject -computer $HostName -credential $Credencial win32_logicaldisk  | Where-Object { $_.DriveType -eq $HardDisk_Type} |  Select-Object DeviceID, FreeSpace

foreach ($Disco in $T)
{

“$HostName has ” + [math]::Round($Disco.FreeSpace/1GB) + ” Gb Free ” + $Disco.DeviceID | out-file $OutputFileName -Append

}

}

Just prepare an input txt file with your server names and you will get a txt file with the results.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s