Batch Script - Dump workstations from AD and check a file version
We recently identified a bug in a widely deployed application and needed to get a count of how many installs mights be subject to issues. Normally I would just walk over to the SMS console and run a report, but sadly our SMS remains less-than-completely-deployed at the moment, and I need a (reasonably) quick answer.
So, here's a batch file to do the job....
Step 1 - Query AD and find all Windows XP workstations
@echo off
::REM ------------------- Begin sample batch script ------------------------
::REM Sample batch programming script
::REM (C)2006 John D. Seaman, Copylefted under terms of the GNU/GPL
::REM by John D. Seaman, www.japan-page.net/batch::REM Change the LDAP
::REM operatingSystem: Windows XP Professional;
::REM Set the base DN
set _baseDN="DC=mydomain,DC=com"
::REM Run a LDAP Query against AD for the OS version you need to find
adfind -b %_baseDN% -f "(operatingSystem=Windows XP Professional)" >out.txt
::REM Extract the machine names
type out.txt | find "cn:" >out2.txt
::REM Optional batch script step - strip the leading "cn: " from the output file with texttools32
::REM Use your favorite batch text editor or do this in notepad later
::REM Strip the "cn: " from the front
type out2.txt | t repl '^>cn: ' '' >out3.txt
:EOF
Once again we use the excellent utility adfind.exe from joeware.net.
Step 2 - Check the target workstations and get the version info
Run a batch script in a loop and query the file in question on the target system. To save time the script will ping the workstation once and if it's offline mark it and skip it.
Gotcha's:
- You have to have sufficient rights on the client workstations.
- You need to know what file and where to find it. This script assumes everything exists in a single location.
- You can do further logic on the versions as needed, this example just divides machines into unreachable, no application found and output if found.
- Output if found is into a file _hostname.out.txt .
- You will have to customize the paths and application names in this example.
- As always, use this and any sample script with the utmost caution. This is provided for educational purposes only.
Take the output of Step 1 above, make sure the "cn: " has been removed and rename the file to machines.txt
@echo off
::REM ------------------- Begin sample batch script ------------------------
::REM Sample batch programming script
::REM (C)2006 John D. Seaman, Copylefted under terms of the GNU/GPL
::REM by John D. Seaman, www.japan-page.net/batch
echo.
echo.
::REM Cleanup old files
if exist _offline-hosts.txt del /q _offline-hosts.txt
if exist _eas-not-found-hosts.txt del /q _eas-not-found-hosts.txt
::REM Set up a loop, process each entry (workstation)
for /f %%i in (machines.txt) do call :queryPC %%i
echo.
echo Done.
pause
goto :EOF
::REM ------------------- F U N C T I O N S -----------------------
::REM Query individual PC and get the info we need...
:queryPC
echo.
echo Now checking PC %1...
::REM Ping the sucker once and make sure it's up...
ping %1 -n 1 >_pingout.txt
type _pingout.txt | find "Request timed out.">nul
goto :result%errorlevel%
:result0
echo Host %1 not pingable, skipping...
echo Host %1 offline >>_offline-hosts.txt
goto :EOF
:result1
echo Host %1 reachable, verifying EAS client install...
if exist \\%1\c$\progra~1\MyApplication\myClient.exe (
echo myClient.exe found...
echo Performing Version check...
filever \\%1\c$\progra~1\MyApplication\myClient.exe >_%1.out.txt
goto :EOF
)
echo MyClient not found in default location on host %1
echo %1 MyClient not found in default location on host %1 >>_application-not-found-hosts.txt
goto :EOF
:EOF
Filever.exe is available in the Windows XP Service Pack 2 Support Tools kit.

NetApp Exchange MSCS cluster SME Backup Script »
Search