Admin Script to Backup User Data Attributes using DsTools
SCRIPT: ADDS_DsTools_DataBackup.cmd
========== BEGINNING OF SCRIPT ==========
@ECHO OFF
SetLocal EnableDelayedExpansion
ECHO ============================================================
ECHO YL Library : ActiveDirectory DsTools
ECHO Backup Data
ECHO Author : Zhang Yunlong
ECHO Blog : ylnotes.blogspot.com
ECHO Filename : ADDS_DsTools_DataBackup.cmd
ECHO ============================================================
ECHO History:
ECHO 1.0 Initial Release
ECHO ============================================================
::------------------------------------------------
::ADDS Container Setup
::------------------------------------------------
::Set Parameter to OU containing User
:: eg. OU=CO_USERS,DC=EXAMPLE,DC=LOCAL
::------------------------------------------------
SET ADDS_USERS_OU=
::------------------------------------------------
::Backup Data
::------------------------------------------------
SET BACKUP_FILE=ADDS_DsTools_DataBackup.txt
SET /A iCounter=1
SET sValue=
> %BACKUP_FILE% ECHO "No","DN","LAN ID","First Name","Last Name","Full Name","IP Phone"
FOR /F "tokens=1 delims=!" %%a IN ('dsquery user "%ADDS_USERS_OU%" -limit 0 -o dn') DO (
SET sValue=
FOR /F "tokens=1 delims=!" %%b IN ('dsget user "%%~a" -dn -samid -fn -ln -display -iptel -L') DO (
IF "%%~b" NEQ "dsget succeeded" (
FOR /F "tokens=2 delims=:" %%c IN ("%%b") DO (
SET sTempValue=%%c
SET sValue=!sValue!^|!sTempValue:~1,1000!
)
)
)
>> %BACKUP_FILE% ECHO !iCounter!!sValue!
SET /A iCounter=!iCounter!+1
)
START NOTEPAD.exe "%BACKUP_FILE%"
EXIT
========== ENDING OF SCRIPT ==========
No comments :
Post a Comment