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 Search this Thread
Search this Thread:

Advanced Search




Similar help and support threads
Thread Forum
Command line - Some questions
I've created a batch file for zipping selected items in a folder. (The file is placed in 'Send to'). If I use the following code: for %%* in (.) do set CurrentFolder=%%~n* "C:\Program Files\WinRar\WinRar" a -afzip "%CurrentFolder%.xpi" The file name is that of the current folder...
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
How can I set this via command-line or registry?
How can I set this via command-line or registry? I need a way to automatically launch "Explorer c:\folder\myfolder" with a view appropriate for long filenames on any Windows Vista/Win7 PC.
Customization
Gpedit via command line
how can I enable disable a policy using gpedit! Not via the GUI, you go do some clicks and enable. But I want to execute one shot command which will say disable AutoRun. I have searched exenstively, no results. I kind need this for my automation stuff. Thanks, Akshay
Performance & Maintenance
How to run a command line utility?
Hi, I am trying to run a command line prompt utility from Microsoft on windows 7. Sure I am doing something wrong, after I click the downloaded .exe file the command prompt pops up briefly then disappears. Can someone explain the basics of running a command line utility on win7? Thanks! ...
General Discussion
Command Line
Is there a cmd.exe /switch for “run as administrator” ? Thanks-
General Discussion


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 15:32.

Twitter Facebook Google+



Windows 7 Forums

Seven Forums Android App Seven Forums IOS App