Category filter
Script to check available disk space on Windows
Low disk space on a device is a significant issue that can negatively impact the performance and productivity of the endpoints. Administrators would want to keep track of the available disk space on a device to check if a required amount of space is present, for instance, to push major OS updates or other company files/resources. Close monitoring of disk spaces is sometimes required to identify any disks that might be clogged with unwanted cache and files. Hexnode UEM lets admins check for the available disk space on Windows devices using custom scripts.
Batch script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
wmic logicaldisk get freespace @echo off SetLocal EnableDelayedExpansion set count=0 for /F "delims=" %%a in ('wmic logicaldisk get freespace') do ( set Zone=%%a set /a count=!count! + 1 if !count! GTR 1 goto Exit ) :Exit echo wsh.echo cdbl(%Zone%)/1073741824 > %temp%.\tmp.vbs for /f %%a in ('cscript //nologo %temp%.\tmp.vbs') do set Zone=%%a del %temp%.\tmp.vbs echo Available Disk Space- %Zone% GB |
This script displays the available disk space in GB.
PowerShell script
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$disks = Get-WmiObject Win32_LogicalDisk -Filter "DriveType = 3" foreach ($disk in $disks) { $freeSpace = "{0:N2}" -f ($disk.FreeSpace/1GB) $totalSpace = "{0:N2}" -f ($disk.Size/1GB) $usedSpace = "{0:N2}" -f ($totalSpace - $freeSpace) $percentFree = "{0:N2}" -f (($freeSpace / $totalSpace) * 100) Write-Host "Drive $($disk.DeviceID) has $freeSpace GB free of $totalSpace GB, $usedSpace GB used, $percentFree % free" } |
This script displays the drive name, available disk space, used space, and the percentage of free space available.