Reputation: 15
looking over google I am trying to create a batch file with output the list of disks and free space. I found a good solution but for each drive listed there is an 1 space empty line (the line start with a space " " and so CR LF for new line). What do you suggest ?
@ECHO OFF
set FILE="testOK.txt"
set IP="127.0.0.1"
set PC="EA"
set TAB=" "
SETLOCAL enableextensions
(for /f "tokens=1-3" %%a in ('
WMIC LOGICALDISK GET FreeSpace^,Name^,Size ^|FINDSTR /I /V "Name"
') do (
echo wsh.echo date ^& %TAB% ^& time ^& %TAB% ^& %ip% ^& %TAB% ^& %PC% ^& %TAB% ^& "%%b" ^& %TAB% ^& FormatNumber^(cdbl^(%%a^)/1024/1024/1024, 2^) ^& " " ^& FormatNumber^(cdbl^(%%c^)/1024/1024/1024, 2^)^& " GB" > "%temp%\tmp.vbs"
if not "%%b"=="" (
echo(
cscript //nologo "%temp%\tmp.vbs"
del "%temp%\tmp.vbs"
)
)
) > %FILE%
Example result:
01/07/2020 10:20:59 10.0.13.36 ADMINPC C: 4,07 69,90 GB
01/07/2020 10:20:59 10.0.13.36 ADMINPC E: 0,00 0,42 GB
Upvotes: 1
Views: 101
Reputation: 38604
In order to keep this answer on topic, here's a batch-file which uses vbscript and wmi, (not wmic), to achieve your goal, and without creating an intermediate .vbs
or all of those variables:
<!-- :
@"%__AppDir__%cscript.exe" //NoLogo "%~f0?.wsf">"testOK.txt"
@Exit /B
-->
<Job><Script Language="VBScript">
Set c=CreateObject("WScript.Network")
Set i=GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
Set o=CreateObject("Scripting.FileSystemObject")
For Each n In i:If n.IPEnabled Then IP=n.IPAddress(0):End If:Next
For Each Drv In o.Drives:If Drv.IsReady=True Then
WScript.Echo Date&VBTab&Time&VBTab&IP&VBTab&c.ComputerName&VBTab&_
Drv.DriveLetter&":"&VBTab&Round(Drv.FreeSpace/1073741824,2)&VBTab&_
Round(Drv.TotalSize/1073741824,2)&" GiB"
End If:Next
</Script></Job>
Upvotes: 1