This script will find the disk usage information of the servers. The computer names are stored in D:\Reports\Computers. Win32_logicaldisk is used to extract the size information of local har drives. The output is stored in D:\Reports\harddisk.csv. The report consists of disk information of all the partitions. The disk size and free size and free size percentage is obtained in the report

PowerShell
Edit|Remove
#create an Empty Array 
$array= @() 
# Open Wmi class Win32_logicaldisk for each computer. Drivetype=3 points to local hard disk 
$computer=Get-Content D:\Reports\computers.txt 
foreach ($server in $computer) 
{ 
 
$dp=Get-WmiObject win32_logicaldisk -ComputerName $server -filter "Drivetype=3" 
 
 
foreach ($item in $dp) 
{ 
$percentfree=[Math]::round((($item.freespace/$item.size)*100)) 
$size = [Math]::round((($item.size/1073741824))) 
$free = [Math]::round((($item.freespace/1073741824))) 
$obj=New-Object PSObject 
$obj |Add-Member -MemberType NoteProperty -Name "ComputerName" $server 
$obj |Add-Member -MemberType NoteProperty -Name "DiskVol" $item.VolumeName 
$obj |Add-Member -MemberType NoteProperty -Name "DeviceID" $item.DeviceID 
$obj |Add-Member -MemberType NoteProperty -Name "Description" $item.Description 
$obj |Add-Member -MemberType NoteProperty -Name "TotalSize" $size 
$obj |Add-Member -MemberType NoteProperty -Name "Freesize" $free 
$obj |Add-Member -MemberType NoteProperty -Name "PercentFree" $percentfree 
$array +=$obj 
} 
 
$array | select ComputerName,DiskVol,DeviceID,Description,TotalSize,Freesize,PercentFree | Export-Csv D:\Reports\harddisk.csv 
}