Command Line - Help

Page 1 of 2 12 LastLast

  1. Posts : 4
    Windows 7 Prof 64bit
       #1

    Command Line - Help


    Hi Guy's and Girls,

    Just first off I've never been too good with CMD and only an Apprentice in my company I work for.

    Now something I've wanted to do for awhile was to make the following but I don't necassirealy I know how to do this in one batch file:

    I would need a Batch file that is able to read the follow;
    Find Current Hard Drive Space and What is used (Dir can do this as far as im aware)
    Convert the CMD information Into either a Excel Document or a .txt format.


    If anyone could lend me a hand with this that would be great.

    P.S the drives I want to make a log of are Server Destinations so i can monitor their disk space daily.

    Regards
    New Member
    Dale :)
      My Computer


  2. Posts : 5,092
    Windows 7 32 bit
       #2

    I don't know if this might help. I have a command line program that gives the free space in B KB MB GB using the largest appropriate. It's df.exe for disk free

    [C:\Program Files\JPSoft\TCCLE13x64]df /?

    df.exe 1.0.9.1 Copyright 2014 favessoft.com

    Usage: df [ C D \\Name\Share ]
    free disk space in one of B KB MB GB

    ( Truncated to 3 decimal places. )

    example:
    [C:\Program Files\JPSoft\TCCLE13x64]df c
    383.848 GB Free on c:

    If you would like to try it, it is free and may be downloaded from my page here:
    Miles Ahead Software

    Edit: you can use command line redirection to output to a file.
    For example to append the result to test.txt you can do
    df c: >>test.txt

    Edit2: You may specify more than one drive on the line.
    Example:
    [C:\Program Files\JPSoft\TCCLE13x64]df c e
    383.848 GB Free on c:
    65.669 GB Free on e:

    [C:\Program Files\JPSoft\TCCLE13x64]
      My Computer


  3. Posts : 2,177
    Windows 8.1 Pro x64
       #3

    I have just quickly put together the below code that outputs the free space in MB and GB if that's any use, it is currently set to output a txt file to the desktop

    Code:
    set tempfile=%userprofile%\desktop\Size.txt
    
    for /f "tokens=1-3" %%n in ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "C:""') do set free=%%n& set total=%%p
    set free=%free:~0,-3%
    set /a free=%free%/1049
    
    echo ------------------------------------------- >%tempfile%
    echo Local Disc Information >>%tempfile%
    echo ------------------------------------------- >>%tempfile%
    echo C: Space Free- %free% MB (approx)>>%tempfile%
    set /a free=%free%/1024
    echo C: Space Free- %free% GB (approx)>>%tempfile%
    I will try and look into space used later.

    Regards,
    Jamie
      My Computer


  4. Posts : 2,177
    Windows 8.1 Pro x64
       #4

    I'm going to have to admit... i have no idea what that big long for loop with what appears to be random characters means in the below code but it works

    It does invoke poswershell if thats ok?
    Again, i have set it to output to a file on the desktop.

    Code:
    SETLOCAL
    set tempfile=%userprofile%\desktop\SpaceUsed.txt
    
    FOR /F "usebackq tokens=1,2" %%f IN (`PowerShell -NoProfile -EncodedCommand "CgBnAHcAbQBpACAAVwBpAG4AMwAyAF8ATABvAGcAaQBjAGEAbABEAGkAcwBrACAALQBGAGkAbAB0AGUAcgAgACIAQwBhAHAAdABpAG8AbgA9ACcAQwA6ACcAIgB8ACUAewAkAGcAPQAxADAANwAzADcANAAxADgAMgA0ADsAWwBpAG4AdABdACQAZgA9ACgAJABfAC4ARgByAGUAZQBTAHAAYQBjAGUALwAkAGcAKQA7AFsAaQBuAHQAXQAkAHQAPQAoACQAXwAuAFMAaQB6AGUALwAkAGcAKQA7AFcAcgBpAHQAZQAtAEgAbwBzAHQAIAAoACQAdAAtACQAZgApACwAJABmAH0ACgA="`) DO ((SET U=%%f)&(SET F=%%g))
    
    echo ------------------------------------------- >%tempfile%
    echo Local Disc Information >>%tempfile%
    echo ------------------------------------------- >>%tempfile%
    echo C: Space Used- %U% GB (approx)>>%tempfile%
    set /a free=%free%/1024
    echo C: Space Free- %F% GB (approx)>>%tempfile%
    Courtesy of a post here which also explains the above in more detail - Windows batch file to get C:\ drive total space and free space available - Stack Overflow

    Example Output

    -------------------------------------------
    Local Disc Information
    -------------------------------------------
    C: Space Used- 75 GB (approx)
    C: Space Free- 223 GB (approx)


    Regards,
    Jamie
      My Computer


  5. Posts : 4
    Windows 7 Prof 64bit
    Thread Starter
       #5

    I've attempted one of the commands given and got it to export into a .txt document however it doesn't like \\ server commands for linking directly to a server (I'm not aware of the Drive Letters my Line Manager has set them as only as the Mapped letters of drives inside the main's.)

    Example; \\****\Svr2
    Map Letter: V:

    Now I can do the maped letter but I need to be able to do it directly to the main drive.

    If this needs explaining I can explain more just changing prices on our till system at the moment as well so it's two things at once :)
      My Computer


  6. Posts : 2,177
    Windows 8.1 Pro x64
       #6

    Dalegolder1994 said:
    I've attempted one of the commands given and got it to export into a .txt document however it doesn't like \\ server commands for linking directly to a server (I'm not aware of the Drive Letters my Line Manager has set them as only as the Mapped letters of drives inside the main's.)

    Example; \\****\Svr2
    Map Letter: V:

    Now I can do the maped letter but I need to be able to do it directly to the main drive.

    If this needs explaining I can explain more just changing prices on our till system at the moment as well so it's two things at once :)
    These commands need running on the server, you appear to have the server mapped as a UNC path which will not work.

    Regards,
    Jamie
      My Computer


  7. Posts : 4
    Windows 7 Prof 64bit
    Thread Starter
       #7

    That's what I Imagined, I've got the drives mapped however, I just need to be able to do it all Externally on a Client machine rather than a Server.
      My Computer


  8. Posts : 1,049
    Windows 7 Pro 32
       #8

    Try this, but replace servername first

    WMIC /node:"servername" LOGICALDISK GET Name,Size,FreeSpace
      My Computer


  9. Posts : 4
    Windows 7 Prof 64bit
    Thread Starter
       #9

    That actually worked thank you :)

    I'll modify both commands given to me to export into a Word Doc and a Batch file to run by schedule.

    Cheers guys!!
      My Computer


  10. Posts : 1,049
    Windows 7 Pro 32
       #10

    I found an example and modified it so it calculates GB correctly + adds on option to list all drives for a server (or localhost).
    The script takes 2 parameters.
    1 = servername
    2 = drive letter

    If you only specify servername you'll see a list of drives.
    If you also specify a drive letter it will display something like this:

    Total space: 94GB
    Free space: 58GB
    Used space: 36GB
    Percent Used: 38%
    Percent Free: 62%

    Code:
    @ECHO OFF
    IF "%~1"=="" goto help
    IF "%~2"=="" goto list
    
    @SETLOCAL ENABLEEXTENSIONS
    @SETLOCAL ENABLEDELAYEDEXPANSION
    
    @FOR /F "tokens=1-3" %%n IN ('"WMIC /node:"%1" LOGICALDISK GET Name,Size,FreeSpace | find /i "%2""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p
    
    echo wsh.echo FormatNumber(cdbl(%TotalBytes%)/1024/1024/1024, 0) > %temp%.\tmp.vbs
    for /f %%a in ('cscript //nologo %temp%.\tmp.vbs') do set TotalBytes=%%a
    del %temp%.\tmp.vbs
    
    echo wsh.echo FormatNumber(cdbl(%FreeBytes%)/1024/1024/1024, 0) > %temp%.\tmp.vbs
    for /f %%a in ('cscript //nologo %temp%.\tmp.vbs') do set FreeBytes=%%a
    del %temp%.\tmp.vbs
    
    SET /A TotalSpace=!TotalBytes!
    SET /A FreeSpace=!FreeBytes!
    SET /A TotalUsed=%TotalSpace% - %FreeSpace%
    SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace!
    SET /A PercentFree=100-!PercentUsed!
    
    IF %TotalSpace% LSS 0 goto error
    
    @ECHO Total space: %TotalSpace%GB
    @ECHO Free space: %FreeSpace%GB
    @ECHO Used space: %TotalUsed%GB
    @ECHO Percent Used: %PercentUsed%%%
    @ECHO Percent Free: %PercentFree%%%
    
    @SET TotalSpace=
    @SET FreeSpace=
    @SET TotalUsed=
    @SET PercentUsed=
    @SET PercentFree=
    goto end
    
    :error
    echo.
    echo *** Invalid server or drive specified ***
    echo.
    goto help
    
    :help
    echo.
    echo Queries remote server for free disk space.
    echo Specify a MACHINENAME and a drive letter to be queried
    echo.
    echo Example:   MACHINENAME c:
    echo.
    goto end
    
    :list
    WMIC /node:"%1" LOGICALDISK GET Name,Size,FreeSpace
    goto end
    
    :end
    Last edited by Tookeri; 12 Sep 2014 at 11:38. Reason: Changed QUOTE to CODE
      My Computer


 
Page 1 of 2 12 LastLast

  Related Discussions
Our Sites
Site Links
About Us
Windows 7 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 7" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 03:45.
Find Us