(view source code of ng_createadlist.bat as plain text)
:: Check for live, non-cluster hosts in current domain@ECHO OFF
:: Get date in YYYYMMDD format - ugly scriptCALL :DateParse
SET FILE=Serverlist.TXT
ECHO FQDN Filename=%1
ECHO USERDOMAIN=%USERDOMAIN%
:: Check if filename with name of FQDN of trusted domain entered:: Note that %1 is the FQDN filename, and MyUSERDOMAIN is the TLD portion of FQDN:: If no FQDN filename specified, then set var for current domain and skip to next sectionIF "%1"=="" SET MyUSERDOMAIN=%USERDOMAIN% && GOTO :Main1
:: From file, get FQDN into MyFQDN, and TLD value into MyUserDomainREM FOR /F %%a IN ('TYPE %1') DO ECHO MyFQDN=%%aFOR /F "tokens=2 delims=." %%a IN ('TYPE %1') DO SET MyUSERDOMAIN=%%a
:Main1:: Display value and remove appending space(s) from string using this code::: http://www.dostips.com/DtTipsStringManipulation.phpSET MyUSERDOMAIN=%MyUSERDOMAIN: =%
ECHO MyUSERDOMAIN=%MyUSERDOMAIN%
SET LOGFILE=%MyUSERDOMAIN%-HostChk_%DateParsed%.csv
ECHO LOGFILE=%LOGFILE%
:: 1) Get all non-disabled hosts & OS version in current domain using ADSI:: Query current domain and put all non-disabled Windows hosts into file serverlist.txtCSCRIPT //nologo CreateListEnabledHosts.vbs %MyUSERDOMAIN%
:: 2) Remove hosts in zombie.txt from Serverlist.txtFINDSTR /I /V /G:zombie.txt Serverlist.txt > realhosts1.txtDEL /Q /F /A Serverlist.txt > nul
REM FINDSTR /I /V /G:DCT.txt realhosts1.txt > Serverlist.txtREN realhosts1.txt Serverlist.txt
:: Delete old results fileIF EXIST %LOGFILE% DEL %LOGFILE%
:: Get each line into a variableFOR /F "delims=" %%a IN (%FILE%) DO SET HOSTINFO=%%a && CALL :LOOP1
IF "%1"=="" ECHO Done!
GOTO :EOF
:: 3) Ping & WMI auth check:LOOP1ECHO.
ECHO hostinfo=%hostinfo%
SET HOSTNAME=
SET ON=0
SET WMIConnect=0
REM SET OS=0:: Get hostname from stringFOR /F "delims=," %%a IN ("%HOSTINFO%") DO SET HOSTNAME=%%a
ECHO hostname=%HOSTNAME%
:: PING -4 forces a IPv4 address and does not error when this option not listed in ping /?PING -4 -n 1 %HOSTNAME% | FIND /I "Reply from" && SET ON=1
:: Setting IP Variable for %HOSTNAME%:: http://stackoverflow.com/a/13201179/1569434REM FOR /F "tokens=2" %%f IN ('nslookup %HOSTNAME%') DO SET IP=%%fFOR /F "tokens=2 delims=[]" %%f IN ('ping -4 -n 1 %HOSTNAME% ^| FIND /I "pinging"') DO SET IP=%%f
:: If power is off, return to EOF (i.e., initial For statement), else continueIF "%ON%"=="0" ECHO %HOSTINFO%,%IP%,PWR%ON%,WMI%WMIConnect%>>%LOGFILE% & GOTO :EOF
:: Proceeding to verify access via WMI...:: Note if %HOSTNAME% contains special characters like '-' or '/' WMIC will:: generate error "invalid global switch". Remedy is to add single quotes around host per::: https://support.quest.com/SolutionDetail.aspx?id=SOL68607WMIC /node:'%HOSTNAME%' ComputerSystem get status /value | find /i "Status=OK" && SET WMIConnect=1
ECHO WMIConnect=%WMIConnect%
IF "%WMIConnect%"=="0" ECHO %HOSTINFO%,%IP%,PWR%ON%,WMI%WMIConnect%>> %LOGFILE% & GOTO :EOF
:: Get OS into variable using this method: http://www.robvanderwoude.com/wmic.php:: It is REMmed out because it's now pulled directly from AD in the VBS script, above, but could be useful later as a reference:: Note the carat "^" is an escape character for pipe "|" and for comma "," in the FOR loopREM FOR /F "tokens=*" %%A IN ('WMIC.EXE /Node:'%HOSTNAME%' Path Win32_OperatingSystem Get /Format:LIST ^|FINDSTR /I /V "version=*"') DO (REM SET OS=%%A)ECHO %HOSTINFO%,%IP%,PWR%ON%,WMI%WMIConnect%>> %LOGFILE%
SET HOSTINFO=
GOTO :EOF
:DateParse:: One of the ugliest scripts required for such a seemingly simple thing is getting dates parsed:: http://www.robvanderwoude.com/datetimentparse.phpSET Today=%Date: =0%
SET Year=%Today:~-4%
:: Include 1 extra character, which will be either a leading zero or a trailing separatorSET Month=%Today:~-10,3%
:: Remove separatorSET Month=%Month:-=%
SET Month=%Month:/=%
:: Clear leading zeroesSET /A Month = 100%Month% %% 100
:: And add one again, if necessarySET /A Month = 100 + %Month%
SET Month=%Month:~-2%
SET Day=%Today:~-7,2%
:: Remove separatorSET Day=%Day:-=%
SET Day=%Day:/=%
:: Clear leading zeroes, as there may be 2 leading zeroesSET /A Day = 100%Day% %% 100
:: And add one again, if necessarySET /A Day = 100 + %Day%
SET Day=%Day:~-2%
SET DateParsed=%year%%month%%day%
GOTO :EOF
page last modified: 2025-10-11; loaded in 0.0050 seconds