Quota Control for windows

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
karzer
Posts: 21
Joined: 17 Jul 2010 02:56

Quota Control for windows

#1 Post by karzer » 27 Jul 2010 07:14

Hi,
I want to do "quota fsutil query d:" command to find users went beyond the 2GB quota?

The output of the command

Code: Select all

SID Comment = hex \ joe (User)
Thu Apr 07 12:34:14 2963 Change time =
Used quota = 94892032
Threshold = quota 792723456
Quota limit = 1073741824

SID Name = hex \ john (User)
Wed Dec 29 16:15:08 2962 Change time =
Used quota = 8192
Quota Threshold = 792723456
Quota limit = 1073741824

SID Name = hex \ Matt (User)
Thu Apr 07 13:08:05 2963 Change time =
Used quota = 249640960
Quota Threshold = 792723456
The output of the command

SID Comment = hex \ Martin (User)
Thu Apr 07 12:34:14 2963 Change time =
Used quota = 94892032
Quota Threshold = 792723456
Quota limit = 1073741824

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Quota Control for windows

#2 Post by aGerman » 27 Jul 2010 07:48

IMO not a good idea to use batch.
As you can see, the value comes in byte. jeb (one of the experts of this forum) teached me that the limit for numeric expressions in batch
is not 4294967295=2^32-1 it is 2147483647 = 2^31-1 because the negative numbers are represented by setting the highest bit

That means if a numer is beyond 2,147,483,647 it is interpreted as negative number, and if a number is beyond 4,294,967,295 it is not interpreted as numeric expression but as alphanumeric expression.
A numeric comparison with numbers beyond 2,147,483,647 will return a wrong result.

Regards
aGerman

karzer
Posts: 21
Joined: 17 Jul 2010 02:56

Re: Quota Control for windows

#3 Post by karzer » 27 Jul 2010 08:49

Thank you for your reply.

!k
Expert
Posts: 378
Joined: 17 Oct 2009 08:30
Location: Russia

Re: Quota Control for windows

#4 Post by !k » 27 Jul 2010 09:40

...the limit for numeric expressions in batch
Just need to divide 'Used quota' for 1000

Code: Select all

@echo off
setlocal enableextensions

fsutil quota query d: >quota.txt
set /a n=0
for /f "tokens=2 delims=\" %%a in ('findstr /b /c:"SID" quota.txt') do call :u "%%a"
set /a n=0
for /f "tokens=2 delims==" %%b in ('findstr /b /c:"Used quota" quota.txt') do call :p %%b
endlocal
echo.
pause
goto :eof

:u
set /a n+=1
set "User%n%=%~1"
goto :eof

:p
set /a n+=1
set Used=%1
set Used=%Used:~0,-3%
if %Used% GTR 2147483 (
echo.
call echo %%User%n%%%
echo Used %1 bytes
)
goto :eof
Last edited by !k on 29 Jul 2010 16:13, edited 1 time in total.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Quota Control for windows

#5 Post by aGerman » 27 Jul 2010 10:14

Good idea, !k.
Otherwise you could source the comparison out to a temporary VBScript.

Regards
aGerman

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Quota Control for windows

#6 Post by aGerman » 27 Jul 2010 19:47

[EDIT]
Was kinda bored, so changed !k's code a bit using VBScript.

Code: Select all

@echo off &setlocal enableextensions

set "LimitGB=2"

>quota.txt fsutil quota query d:

>"%temp%\c.vbs" echo x=WScript.Arguments(0)/1073741824:If x^>WScript.Arguments(1)*1 Then:a="NOK":Else:a="OK":End If:WScript.Echo a^&":"^&FormatNumber(x,3,,,0)

set /a n=0
for /f "tokens=2,3 delims==\(" %%a in ('findstr /b /c:"SID" quota.txt') do call :u "%%a" "%%b"
set /a n=0
for /f "tokens=2 delims==" %%b in ('findstr /b /c:"Used quota" quota.txt') do call :p %%b
del "%temp%\c.vbs"
echo.
endlocal
pause
goto :eof

:u
set /a n+=1
set "SID%n%=%~1"
set "User%n%=%~2"
goto :eof

:p
set /a n+=1
:: The script needs quota[byte] and limit[GB] as input parameters
:: and returns status[OK/NOK] and quota[GB] separated by colon
for /f "delims=: tokens=1*" %%a in ('cscript //nologo "%temp%\c.vbs" "%~1" "%LimitGB%"') do (
  set "Status=%%a" &set "GB=%%b"
)
call echo %Status% %GB% %%SID%n%:~1,-1%% %%User%n%:~1,-1%%
goto :eof

You could change the output line to display only the NOK lines:
call echo %Status% %GB% %%SID%n%:~1,-1%% %%User%n%:~1,-1%% | findstr /b "NOK"

[/EDIT]

Post Reply