Ordner größe ermitteln
Hallo, möchte gerne die größe eines ordners ermitteln und dann das ergebnis in eine Datei schreiben und das granze mit einem Batch (oder anderm Format) scribt machen.
Kann mir jemand helfen???
Kann mir jemand helfen???
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 24168
Url: https://administrator.de/forum/ordner-groesse-ermitteln-24168.html
Ausgedruckt am: 23.12.2024 um 04:12 Uhr
4 Kommentare
Neuester Kommentar
Hallo!
Also ich hatte selbiges Problem, um Usern anhand des belegten Platzes in entsprechenden Quota-Gruppen zu verfrachten. Ich habe mit mit TreeSize Pro einen Export mit Username und belegten MB gezogen und dann mit dem folgenden Skript (danke Andi ) die Zuordnungen in die AD-Gruppen gemacht:
Skript ist in W2003-Command-Shell.
:: Written 18.11.05 by loan
:: Version 1.00
@echo OFF
CLS
:: VARs AND CHECKS
::
SET PROCFILE=%1
SET TEST=%2
IF [%PROCFILE%] == GOTO SYNTAX
ECHO.
ECHO This script is designed to scan a Textfile, read the occupied space per user
ECHO and add the user to the appropriate AD-QuotaGroup (GROUPS).
ECHO.
ECHO File '%PROCFILE%' will be processed.
ECHO.
ECHO All actions are logged in:
ECHO %CD%\QUOTA.LOG.
ECHO.
IF DEFINED TEST ECHO Started in TESTMODE. Nothing will be changed in AD.
ECHO.
ECHO Press CTRL+C to exit now!
PAUSE
ECHO. >>%CD%\QUOTA.LOG
ECHO. >>%CD%\QUOTA.LOG
ECHO ---------------------- >>%CD%\QUOTA.LOG
ECHO Batch started at %DATE% - %TIME% by %USERNAME% >>%CD%\QUOTA.LOG
IF DEFINED TEST ECHO Started in TESTMODE. Nothing will be changed in AD. >>%CD%\QUOTA.LOG
:: Some Prereq's
::
IF NOT EXIST %PROCFILE% GOTO PROCFILE
:: Do the Work with the final list
::
ECHO Applying changes. Please wait...
FOR /F "delims=; tokens=1,2" %%J IN (%PROCFILE%) DO CALL :SUB02 %%K %%J
GOTO ENDE
:: SUBS
::
:: Main Process
::
:SUB02
SET SPACE=%1
SET QUSER=%2
rem echo Space [%SPACE%]
rem echo QUser [%QUSER%]
rem pause
ECHO.
:: Checking for User in AD
ECHO Searching User %QUSER% in AD...
DSQUERY user -samid %QUSER% | find /i "CN=" >NUL
:: No matching User for Dir found
IF ERRORLEVEL 1 ECHO Directory/User '%QUSER%' NOT found in AD. Skipping! && ECHO. >>%CD%\Quota.log && ECHO Directory/User %QUSER% NOT found in AD. Skipping! >>%CD%\Quota.log && GOTO EOF
:: Checking for Quota GroupMembership, User MUST NOT BE in any other Home-QuotaGroup
ECHO User '%QUSER%' has allocated '%SPACE%' MB.
Echo Searching User %QUSER% in '-GC-QUOTA-GROUPS' Groups...
DSQUERY user -samid %QUSER% | dsget user -memberof | find /I "-GC-QUOTA-GROUPS" >NUL
IF ERRORLEVEL 1 GOTO ALLOK1
IF ERRORLEVEL 0 ECHO User '%QUSER%' already in another GROUPS-quota group. Skipping! && ECHO. >>%CD%\Quota.log && ECHO User '%QUSER%' already in another home-quota group. Skipping! >>%CD%\Quota.log && GOTO EOF
:AllOK1
::User and Dir Found, proceeding
ECHO. >>%CD%\Quota.log && ECHO User '%QUSER%' has allocated '%SPACE%' MB >>%CD%\Quota.log
IF %SPACE% GTR 3800 GOTO MBUNLIM
IF %SPACE% GTR 1800 GOTO MB4000
IF %SPACE% GTR 800 GOTO MB2000
IF %SPACE% GTR 450 GOTO MB1000
IF %SPACE% GTR 180 GOTO MB500
IF %SPACE% GTR 80 GOTO MB200
GOTO MB100
GOTO :EOF
:MBUNLIM
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-UNLIMITED,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB4000
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-4GB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB2000
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-2GB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB1000
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-1GB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB500
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-500MB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB200
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-200MB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB100
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-100MB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
GOTO :EOF
:ADDUSER2GROUP
IF DEFINED TEST GOTO :EOF
ECHO Adding User '%QUSER%' to %QGROUP%
DSQUERY user -samid %QUSER% | DSMOD group %QGROUP% -addmbr >>%CD%\Quota.log
GOTO :EOF
GOTO ENDE
:: How to use
:SYNTAX
CLS
ECHO.
ECHO Usage: quota 'ListFile.txt' 'test'
ECHO.
ECHO Example: quota C:\TXT\UsrSpace.txt 12345
ECHO.
ECHO ListFile.txt must be ...
ECHO ... a semicolon-delimited textfile
ECHO ... first colum must contain the user LoginID (SAMID)
ECHO ... second colum must contain the used Space in MB
ECHO.
ECHO The second parameter 'test' can be whatwever you
ECHO want. If it is defined, nothing will be changed
ECHO in your AD but everything is logged to file.
ECHO This can be used as a preflight-check.
ECHO.
GOTO ENDE
:: Listfile missing
:PROCFILE
CLS
ECHO.
ECHO List File not found.
ECHO [%PROCFILE%]
ECHO.
GOTO ENDE
:: Leaving
::
:EOF
:ENDE
Gruss
Udo
Also ich hatte selbiges Problem, um Usern anhand des belegten Platzes in entsprechenden Quota-Gruppen zu verfrachten. Ich habe mit mit TreeSize Pro einen Export mit Username und belegten MB gezogen und dann mit dem folgenden Skript (danke Andi ) die Zuordnungen in die AD-Gruppen gemacht:
Skript ist in W2003-Command-Shell.
:: Written 18.11.05 by loan
:: Version 1.00
@echo OFF
CLS
:: VARs AND CHECKS
::
SET PROCFILE=%1
SET TEST=%2
IF [%PROCFILE%] == GOTO SYNTAX
ECHO.
ECHO This script is designed to scan a Textfile, read the occupied space per user
ECHO and add the user to the appropriate AD-QuotaGroup (GROUPS).
ECHO.
ECHO File '%PROCFILE%' will be processed.
ECHO.
ECHO All actions are logged in:
ECHO %CD%\QUOTA.LOG.
ECHO.
IF DEFINED TEST ECHO Started in TESTMODE. Nothing will be changed in AD.
ECHO.
ECHO Press CTRL+C to exit now!
PAUSE
ECHO. >>%CD%\QUOTA.LOG
ECHO. >>%CD%\QUOTA.LOG
ECHO ---------------------- >>%CD%\QUOTA.LOG
ECHO Batch started at %DATE% - %TIME% by %USERNAME% >>%CD%\QUOTA.LOG
IF DEFINED TEST ECHO Started in TESTMODE. Nothing will be changed in AD. >>%CD%\QUOTA.LOG
:: Some Prereq's
::
IF NOT EXIST %PROCFILE% GOTO PROCFILE
:: Do the Work with the final list
::
ECHO Applying changes. Please wait...
FOR /F "delims=; tokens=1,2" %%J IN (%PROCFILE%) DO CALL :SUB02 %%K %%J
GOTO ENDE
:: SUBS
::
:: Main Process
::
:SUB02
SET SPACE=%1
SET QUSER=%2
rem echo Space [%SPACE%]
rem echo QUser [%QUSER%]
rem pause
ECHO.
:: Checking for User in AD
ECHO Searching User %QUSER% in AD...
DSQUERY user -samid %QUSER% | find /i "CN=" >NUL
:: No matching User for Dir found
IF ERRORLEVEL 1 ECHO Directory/User '%QUSER%' NOT found in AD. Skipping! && ECHO. >>%CD%\Quota.log && ECHO Directory/User %QUSER% NOT found in AD. Skipping! >>%CD%\Quota.log && GOTO EOF
:: Checking for Quota GroupMembership, User MUST NOT BE in any other Home-QuotaGroup
ECHO User '%QUSER%' has allocated '%SPACE%' MB.
Echo Searching User %QUSER% in '-GC-QUOTA-GROUPS' Groups...
DSQUERY user -samid %QUSER% | dsget user -memberof | find /I "-GC-QUOTA-GROUPS" >NUL
IF ERRORLEVEL 1 GOTO ALLOK1
IF ERRORLEVEL 0 ECHO User '%QUSER%' already in another GROUPS-quota group. Skipping! && ECHO. >>%CD%\Quota.log && ECHO User '%QUSER%' already in another home-quota group. Skipping! >>%CD%\Quota.log && GOTO EOF
:AllOK1
::User and Dir Found, proceeding
ECHO. >>%CD%\Quota.log && ECHO User '%QUSER%' has allocated '%SPACE%' MB >>%CD%\Quota.log
IF %SPACE% GTR 3800 GOTO MBUNLIM
IF %SPACE% GTR 1800 GOTO MB4000
IF %SPACE% GTR 800 GOTO MB2000
IF %SPACE% GTR 450 GOTO MB1000
IF %SPACE% GTR 180 GOTO MB500
IF %SPACE% GTR 80 GOTO MB200
GOTO MB100
GOTO :EOF
:MBUNLIM
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-UNLIMITED,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB4000
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-4GB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB2000
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-2GB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB1000
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-1GB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB500
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-500MB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB200
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-200MB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
:MB100
SET QGROUP=
SET QGROUP="CN=-GC-QUOTA-GROUPS-100MB,OU=Groups,OU=ou-Schweiz,DC=DOMÄNE,DC=local"
ECHO %QUSER% %SPACE% (%QGROUP%)
ECHO User '%QUSER%' will be added to %QGROUP% >>%CD%\Quota.log
GOTO ADDUSER2GROUP
GOTO :EOF
:ADDUSER2GROUP
IF DEFINED TEST GOTO :EOF
ECHO Adding User '%QUSER%' to %QGROUP%
DSQUERY user -samid %QUSER% | DSMOD group %QGROUP% -addmbr >>%CD%\Quota.log
GOTO :EOF
GOTO ENDE
:: How to use
:SYNTAX
CLS
ECHO.
ECHO Usage: quota 'ListFile.txt' 'test'
ECHO.
ECHO Example: quota C:\TXT\UsrSpace.txt 12345
ECHO.
ECHO ListFile.txt must be ...
ECHO ... a semicolon-delimited textfile
ECHO ... first colum must contain the user LoginID (SAMID)
ECHO ... second colum must contain the used Space in MB
ECHO.
ECHO The second parameter 'test' can be whatwever you
ECHO want. If it is defined, nothing will be changed
ECHO in your AD but everything is logged to file.
ECHO This can be used as a preflight-check.
ECHO.
GOTO ENDE
:: Listfile missing
:PROCFILE
CLS
ECHO.
ECHO List File not found.
ECHO [%PROCFILE%]
ECHO.
GOTO ENDE
:: Leaving
::
:EOF
:ENDE
Gruss
Udo
Moin ABC,
mein Grundgerüst für diesen Zweck:
Die Unterordner werden bei der Größenermittlung immer mit eingeschlossen.
HTH Biber
mein Grundgerüst für diesen Zweck:
::------snipp Dirsize.bat (Parameter Verzeichnisname
@echo off & setlocal
Set DIRCMD=
If exist %1 (
for /f "tokens=3" %%c in ('dir %1 /s ^| findstr /c:Datei^(en^) ') do set DirSize=%%c
REM Bei EN-US: for /f "tokens=3" %%c in ('dir %1 /s ^| findstr /c:File^(s^) ') do set DirSize=%%c
)
if defined DirSize echo %DirSize%
::------snapp Dirsize.bat
HTH Biber