Batch – Credant – Create DCID Report

email me

@echo off
cls
color 3a
@title=Query and Log DCID


::Create report name
for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
(set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p) ) )
For /F "tokens=1,2 delims=:, " %%i in ('TIME /T') Do (Set HHMM=%%i%%j)

@Echo off > g:\DCID\Report_%mm%-%dd%-%yy%_%HHMM%.txt

@Del /q g:\dcid\next.txt

goto MAIN

:STATUS
for /f "tokens=* delims= " %%c in (g:\dcid\mstcomputers.txt) do (
ping %%c -n 1 -w 250 | find "Reply" > nul
if errorlevel 1 (echo %%c OFFLINE & echo %%c>>g:\dcid\next.txt
) else (
ECHO %%c>> g:\dcid\computers.txt
ECHO %%c Online
)
)

:MAIN
for /f "tokens=* delims= " %%a in (g:\dcid\computers.txt) do set PC=%%a& call :LOG
goto END

:LOG
for /f "tokens=2 delims=\" %%e in ('wmic /node:"%PC%" ComputerSystem Get UserName') do set UserName=%%e
set UserName=%UserName: =%
FOR /F "tokens=3* delims=	" %%B IN ('Reg query "\\%PC%\HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\CMGShield" /v DCID') DO SET VAR=%%B
ECHO %PC%,%VAR%,%UserName% >> g:\dcid\Report_%mm%-%dd%-%yy%_%HHMM%.txt
ECHO %PC%,%VAR%,%UserName%
set UserName=
goto END

:END
pause
exit /b 0