Windows 7 Forums
Welcome to Windows 7 Forums. Our forum is dedicated to helping you find support and solutions for any problems regarding your Windows 7 PC be it Dell, HP, Acer, Asus or a custom build. We also provide an extensive Windows 7 tutorial section that covers a wide range of tips and tricks.


Windows 7: Command Line - Help

12 Sep 2014   #1
Dalegolder1994

Windows 7 Prof 64bit
 
 
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 System SpecsSystem Spec
.
12 Sep 2014   #2
MilesAhead

Windows 7 32 bit
 
 

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 System SpecsSystem Spec
12 Sep 2014   #3
JDobbsy1987

Windows 8.1 Pro x64
 
 

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 System SpecsSystem Spec
.

12 Sep 2014   #4
JDobbsy1987

Windows 8.1 Pro x64
 
 

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 System SpecsSystem Spec
12 Sep 2014   #5
Dalegolder1994

Windows 7 Prof 64bit
 
 

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 System SpecsSystem Spec
12 Sep 2014   #6
JDobbsy1987

Windows 8.1 Pro x64
 
 

Quote   Quote: Originally Posted by Dalegolder1994 View Post
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 System SpecsSystem Spec
12 Sep 2014   #7
Dalegolder1994

Windows 7 Prof 64bit
 
 

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 System SpecsSystem Spec
12 Sep 2014   #8
Tookeri

Windows 7 Pro 32
 
 

Try this, but replace servername first

WMIC /node:"servername" LOGICALDISK GET Name,Size,FreeSpace
My System SpecsSystem Spec
12 Sep 2014   #9
Dalegolder1994

Windows 7 Prof 64bit
 
 

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 System SpecsSystem Spec
12 Sep 2014   #10
Tookeri

Windows 7 Pro 32
 
 

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
My System SpecsSystem Spec
Reply

 Command Line - Help




Thread Tools




Similar help and support threads
Thread Forum
Executing command line command anywhere ?
I want to create a setup whereas a command line command can be run from any directory/folder, without having to be in the directory/folder whereas the command line command resides ?
General Discussion
What is wrong with this command line?
Help please I am pulling my hair out. I use a desktop shortcut to run an application called get_iplayer.cmd located in the directory c:\program files\get_iplayer The line in the Target of the shortcut properties therefore reads: C:\Windows\System32\cmd.exe /k "c:\program...
General Discussion
UAC bug with runas from command line?
Hi Folks, I am experiencing what I believe is a bug with UAC in Windows 7. I would like to see if anyone can recreate this issue and tell me if it is a bug or is working as expected. To recreate the issue: 1. Confirm the following local security policy setting is Enabled. Local Policies...
General Discussion
Command Line
Is there a cmd.exe /switch for “run as administrator” ? Thanks-
General Discussion
Can you boot from the command line?
This is an off topic thread because it concerns WinXP/2000 dual boot machine which are not booting. I can get to the Windows\ and Winnt command line of each but trying to figure out if I can boot from there. If I try to boot regularly I get "missing operating system" Im trying the Windows 2000...
Chillout Room


Our Sites

Site Links

About Us

Find 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 10:45.
Twitter Facebook Google+