A little PowerShell Script that collects disk space data from remote servers.
I found this practical to collect statistical data.
###############################################################
_#####################
# This script counts and calculated available and free disk
_ spare on remote servers
#
# A WMI query is used to collect the data
#
# Target servers and disks are in a separate comma-delimited
_ text file
###############################################################
_#####################
# Input file location
$InputFile = "ServersAndDisks.txt"
# Loop through each line of the input file
ForEach ($Line in $(Get-Content $InputFile))
{
# Write line data into an array
$Data = $Line.Split(",")
# Get the server name (always first element of the array)
$ServerName = $Data[0]
write-host $ServerName
# Loop through the remaining elements of the array to find
_ available disks
For ($Count = 1; $Count -le $Data.GetUpperBound(0); $Count++)
{
# Get the disk name
$Disk = $Data[$Count]
# Run the WMI query
$DiskInfo = Get-WmiObject Win32_LogicalDisk -ComputerName
_$ServerName -Filter "DeviceID='$Disk'"
# Do some math on the data
$DiskTotal = [math]::Round($DiskInfo.Size / 1GB, 1)
$DiskFree = [math]::Round($DiskInfo.FreeSpace / 1GB, 1)
$PercentageFree = [math]::Round($DiskInfo.FreeSpace /
_$DiskInfo.Size * 100, 1)
# Output the results
Write-Host "$Disk - $DiskTotal GB Total / $DiskFree GB free
_ ($PercentageFree %)"
}
}
The input file
ServersAndDisks.txt is very simple - only a comma-delimited file with server name and the disks I want to check:
server001,C:,D:
server002,C:,D:
server003,D: