Page 1 of 1
Quota Control for windows
Posted: 27 Jul 2010 07:14
by karzer
Hi,
I want to do "quota fsutil query d:" command to find users went beyond the 2GB quota?
The output of the commandCode: 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
Re: Quota Control for windows
Posted: 27 Jul 2010 07:48
by aGerman
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
Re: Quota Control for windows
Posted: 27 Jul 2010 08:49
by karzer
Thank you for your reply.
Re: Quota Control for windows
Posted: 27 Jul 2010 09:40
by !k
...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
Re: Quota Control for windows
Posted: 27 Jul 2010 10:14
by aGerman
Good idea, !k.
Otherwise you could source the comparison out to a temporary VBScript.
Regards
aGerman
Re: Quota Control for windows
Posted: 27 Jul 2010 19:47
by aGerman
[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]