JSI Tip 7823. How can I generate a CSV file of all the computers in my domain, showing their O/S, version, service pack, product name, and roles?

Jerold Schulman

March 10, 2004

2 Min Read
ITPro Today logo in a gray background | ITPro Today

I have scripted AllComputers.bat to generate CSV list of all the computers in a domain, showing the O/S, version, service pack, product name, and roles. The roles include:

Domain Controller (Y/N)
Global Catalog (Y/N)
"Schema","Domain naming","PDC","RID", and "Infrastructure"  FSMO masters,

like the following sample:

"JSI001","5.2","Service Pack 1  v.1159","Microsoft Windows Server 2003","Y","Y","Schema","Domain","PDC","RID","Infrastructure""JSI009","5.1","Service Pack 2  v.2082","Microsoft Windows XP","N","N","","","","","""JSI005","5.0","Service Pack 4","Microsoft Windows 2000","N","N","","","","","""JSI003","5.1","Service Pack 1","Microsoft Windows XP","N","N","","","","","""JSI007","5.2","None","Microsoft Windows Server 2003","N","N","","","","",""

The syntax for using AllComputers.bat is:

AllComputers.

The CSV list is displayed on the console, put you can pipe it to a file using:

AllComputers>FileName.

NOTE: AllComputers.bat uses AllFSMO.bat and IsGC.bat.

NOTE: If NETDOM.EXE is not installed on the computer you will use to run AllComputers.bat, install it from the Support / Tools folder of your O/S CD-ROM.

AllComputers.bat contains:

@echo offsetlocal ENABLEDELAYEDEXPANSIONset netdm=netdom query /domain:%userdnsdomain%set dc=Yfor /f "Skip=1 Tokens=*" %%c in ('%netdm% dc^|find /v /i "The command completed successfully."') do ( set cmp=%%c call :doit)set dc=Nfor /f "Skip=1 Tokens=*" %%c in ('%netdm% server^|find /v /i "The command completed successfully."') do ( set cmp=%%c call :doit)for /f "Skip=1 Tokens=*" %%c in ('%netdm% workstation^|find /v /i "The command completed successfully."') do ( set cmp=%%c call :doit)endlocalexit /b 0:doitset work=%cmp:     ( Workstation or Server )=%if "%work%" NEQ "%cmp%" set cmp=%work%#set cmp=%cmp: #=%set cmp=%cmp:#=%set cv=set sp=set pn=set gc=Nfor /f "Tokens=2*" %%r in ('reg query "\%cmp%HKLMSOFTWAREMicrosoftWindows NTCurrentVersion" /v CurrentVersion^|find "REG_SZ"') do set cv=%%sfor /f "Tokens=2*" %%r in ('reg query "\%cmp%HKLMSOFTWAREMicrosoftWindows NTCurrentVersion" /v ProductName^|find "REG_SZ"') do set pn=%%sset pn=!pn:,= !call :csdv>nul 2>&1if "%dc%" EQU "Y" call isgc "%cmp%" gcif "%dc%" EQU "Y" for /f "Tokens=1-6" %%r in ('AllFSMO') do ( set role1=%%s set role2=%%t set role3=%%u set role4=%%v set role5=%%w)@echo "%cmp%","!cv!","!sp!","!pn!","!dc!","!gc!","!role1!","!role2!","!role3!","!role4!","!role5!"if  "%dc%" EQU "Y"  set role1=&set role2=&set role3=&set role4=&set role5=goto :EOF:csdvset sp=Nonefor /f "Tokens=2*" %%r in ('reg query "\%cmp%HKLMSOFTWAREMicrosoftWindows NTCurrentVersion" /v CSDVersion^|find "REG_SZ"') do set sp=%%sset sp=!sp:,= !

NOTE: See tip 7717 More on DSQUERY attribute filtering.



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like