JSI Tip 5615. How do I locate the 'dead' computers in Active Directory?

I get asked this question so many times, that I decided to script a solution.

The Domain_Computer.bat script is designed to be run multiple times, during a time period that most computers would likely be powered on. It pings every computer in the "Domain Computers" group and tracks their response. It creates a Domain_Computers folder on your workstation, on the same partition as Domain_Computer.bat, and creates a file for every computer, where the file name is the computer name and the extension is the number of times that the computer responded. 'Dead' computers have a .0000 extension. If you run this script 8 times in a month, most 'live' computers will have an extension of .0008. The file creation date will tell you the last time that a computer responded. You can periodically delete all the files and start over.

Domain_Computer.bat contains:

@echo off
set drive=%~d0
if not exist %drive%\Domain_Computers MD Domain_Computers
pushd %drive%\Domain_Computers
for /f "Skip=8 Tokens=*" %%w in ('net Group "Domain Computers" /domain') do set line=%%w&call :parse
goto :EOF
set workstn=%line:~0,25%#
If /i "%workstn%" EQU "The command completed suc#" goto :EOF
call :parse1
set workstn=%line:~25,25%#
if not "%workstn%" EQU "#" call :parse1
set workstn=%line:~50,25%#
if not "%workstn%" EQU "#" call :parse1 
goto :EOF
set workstn=%workstn:  =%
set workstn=%workstn: #=%
set workstn=%workstn:#=%
set workstn=%workstn:$=%
set OK=Y
for /f "Tokens=1" %%a in ('ping -n 1 %workstn%') do set response=%%a&call :isok
if /i "%OK%" EQU "Y" goto postok
if /i "%OK%" EQU "N" goto postno
if exist %workstn%.* del /q %workstn%.*
goto :EOF
if exist %workstn%.* goto :EOF
goto :EOF
if not exist %workstn%.* @echo.>%workstn%.0000
for /f "Tokens=2 Delims=." %%b in ('dir /b %workstn%.*') do set times=%%b
set /a times=1%times% + 1
set times=%times:~1,4%
del /q %workstn%.*
goto :EOF
If /i "%response%" EQU "Request" set OK=N&goto :EOF
If /i "%response%" EQU "Unknown" set OK=U&goto :EOF

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.