2019-03-26

Windows Command line get disk space in GB, export to a file.



Reference URL: https://superuser.com/a/924992



Debug mode to understand this script.

del diskspace.log & for /f "tokens=1-3" %a in ('WMIC LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"') do @echo wsh.echo "%b" ^& " Free=" ^& FormatNumber^(cdbl^(%a^)/1024/1024/1024, 2^)^& " GiB"^& " Size=" ^& FormatNumber^(cdbl^(%c^)/1024/1024/1024, 2^)^& " GiB"^& " Used=" ^& FormatNumber^(cdbl^(%c^-%a^)/1024/1024/1024, 2^)^& " GiB" > %temp%\tmp.vbs & more %temp%\tmp.vbs & @if not "%c"=="" @echo( & @cscript //nologo %temp%\tmp.vbs >> diskspace.log & more diskspace.log




Production script:

del diskspace.log & for /f "tokens=1-3" %a in ('WMIC LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"') do @echo wsh.echo "%b" ^& " Free=" ^& FormatNumber^(cdbl^(%a^)/1024/1024/1024, 2^)^& " GiB"^& " Size=" ^& FormatNumber^(cdbl^(%c^)/1024/1024/1024, 2^)^& " GiB"^& " Used=" ^& FormatNumber^(cdbl^(%c^-%a^)/1024/1024/1024, 2^)^& " GiB" > %temp%\tmp.vbs & @if not "%c"=="" @echo( & @cscript //nologo %temp%\tmp.vbs >> diskspace.log

more diskspace.log








No comments:

Post a Comment