Below is code I used for a project to strip data from WinMSD export files.
code:
; REM Script will run through MSD Text files to pull relevant data.
; REM 2001.03.27
; REM ** Set global variables
$ChkDom = ""
$Drv = "C:"
$Dir = "\<dir>\<folder>"
$WorkDir = "$Drv$Dir"
$CR = CHR(13) + CHR(10) ; REM ** Carriage returns
$ChkList = "chklist.txt" ; REM ** Contains read list of all defined Domain Members (WinNT/2K) for Kix Script.
$MemList = "memlist.txt" ; REM ** Contains raw list of all defined Domain Members (WinNT/2K).
$MsdList = "msdlist.txt" ; REM ** Contains domain member list to run WinMSD and Net View commands.
$NTDet = "nt_det.txt" ; REM ** Kix output file for Detail system data from WinMSD files.
$NTShr = "nt_shr.txt" ; REM ** Kix output file for Shared Resource data from WinMSD files.
$NTSvc = "nt_svc.txt" ; REM ** Kix output file for Services data from WinMSD files.
SELECT
CASE (@DOS = "5.0")
$RC = MESSAGEBOX ("This script only runs with WinNT 4.0 utilities, not Win2K which is your operating system.","NOTICE",64)
$RC = MESSAGEBOX ("You must have the WinNT 4.0 'Winmsd.exe' utility on your system, in your local path, and named 'WinmsdNT.exe.","NOTICE",64)
$RC = MESSAGEBOX ("You must have the WinNT 4.0 'Netdom.exe' utility on your system, in your local path, and named 'NetdomNT.exe.","NOTICE",64)
$RC = MESSAGEBOX ("Confirm 'WinmsdNT.exe' and 'NetdomNT.exe' on your system. Press 'Yes' to Continue, 'No' to abort.","NOTICE",20)
IF $RC = 6 ; REM ** '6' = 'Yes' button selected, 7 ='NO' button.
$Msd = "Winmsdnt"
$Net = "Netdomnt"
ELSE
$RC = MESSAGEBOX ("Aborting process until 'Winmsd.exe' and 'Netdom.exe' verified for correct versions installed.","NOTICE",64)
EXIT
ENDIF
CASE (@DOS = "4.0")
$Msd = "Winmsd"
$Net = "Netdom"
ENDSELECT
REM ** Obtains list of WinNT/2K Domain members to query from a file.
SHELL "%COMSPEC% /c $Drv"
SHELL "%COMSPEC% /c CD $Dir"
SHELL "%COMSPEC% /c $Net /d:$ChkDom Member > $MemList"
SHELL "%COMSPEC% /c $Net /d:$ChkDom BDC >> $MemList"
OPEN (1, "$MemList") ; REM ** 'Read'-file to massage for member names.
OPEN (2, "$ChkList", 5) ; REM ** 'Write'-file to hold new data
OPEN (3, "$MsdList", 5) ; REM ** INTERACTIVE batch file to run WINMSD and NET VIEW on domain members.
:NAME_LOOP
$Read = READLINE (1)
SELECT
CASE (@ERROR <> 0) EXIT
CASE (@ERROR = 0)
SELECT
CASE INSTR ($Read, "Listing members of domain")
$Read = READLINE (1)
DO
$Read = READLINE (1)
IF INSTR ($Read, "MEMBER")
$Name = SUBSTR ($Read, 16, LEN($Read))
$Console = WRITELINE (2, "$Name.txt" + $CR)
$Console = WRITELINE (3, "$MSD \\$Name /s" + $CR)
$Console = WRITELINE (3, "NET VIEW \\$Name > $Name.txt" + $CR)
ENDIF
UNTIL (INSTR ($Read, "MEMBER") = 0)
CASE INSTR ($Read, "Listing BDCs")
$Read = READLINE (1)
DO
$Read = READLINE (1)
IF INSTR ($Read, "BDC")
$Name = SUBSTR ($Read, 13, LEN($Read))
$Console = WRITELINE (2, "$Name.txt" + $CR)
ENDIF
UNTIL (INSTR ($Read, "BDC") = 0)
GOTO EXIT_NAME
ENDSELECT
GOTO NAME_LOOP
ENDSELECT
:EXIT_NAME
$Console = CLOSE (1)
$Console = CLOSE (2)
$Console = CLOSE (3)
; REM ** Start WinMSD batch file to query domain members
SHELL "%COMSPEC% /c $MsdList"
SHELL "%COMSPEC% /c MOVE $ChkList.@DATE"
SHELL "%COMSPEC% /c MOVE $MemList.@DATE"
SHELL "%COMSPEC% /c MOVE $MSDList.@DATE"
SHELL "%COMSPEC% /c DIR *.txt > runlist.txt" ; REM ** Get list of all text files to check for MSD data.
; REM ** Export data from workstation/server files into 3 consolidated files in pipe-delimited format.
$Console = OPEN (1, "$WorkDir\runlist.txt")
$Console = OPEN (7, "$WorkDir\$NTDet", 5)
$Console = OPEN (8, "$WorkDir\$NTSvc", 5)
$Console = OPEN (9, "$WorkDir\$NTShr", 5)
$Console = WRITELINE (7, "System Name|Domain|Role|OS|Service Pack|Procssor1|Processor2|Comment|Product Number" + $CR)
$Console = WRITELINE (8, "System Name|Role|OS|Services" + $CR)
$Console = WRITELINE (9, "System Name|Domain|Role|OS|Defined Share" + $CR)
:FILE_LOOP
$File = READLINE (1)
$Console = OPEN (2, "$WorkDir\$File")
SELECT
CASE ($File < "000000") ; REM ** Extra blank line at end of file.
GOTO EXIT_LOOP
CASE ($Console = "0")
$Read = READLINE (2)
$Read = READLINE (2)
$Read = READLINE (2)
$Read = READLINE (2)
$Read = READLINE (2)
$SysNam = UCASE (SUBSTR ($Read, 36, LEN($Read)))
$x2=1
WHILE ((@ERROR=0) AND ($x2 <> "6"))
$Read = READLINE (2)
SELECT
CASE INSTR ($Read, "OS Version Report")
$Read = READLINE (2)
$Read = READLINE (2)
$Role = SUBSTR ($Read, 31, LEN($Read))
$Read = READLINE (2)
$Ver = SUBSTR ($Read, 9, 3)
SELECT
CASE ($Ver = "4.0")
$Ver = "Windows NT"
$SvcPk = SUBSTR ($Read, 40, 1)
CASE ($Ver = "5.0")
$Ver = "Windows 2000"
SELECT
CASE (SUBSTR ($Read, 42, 2) = "RC") $SvcPk = SUBSTR ($Read, 39, 9) ; REM ** SP1 w/Recovery Console
CASE (SUBSTR ($Read, 40, 1) = "1") $SvcPk = SUBSTR ($Read, 40, 1) ; REM ** SP1 w/o Recovery Console
CASE (SUBSTR ($Read, 40, 1) <> "1") $SvcPk = "0" ; REM ** No Service Pack
ENDSELECT
CASE (1)
$Ver = "Unknown ?"
ENDSELECT
$Read = READLINE (2)
$Read = READLINE (2)
$ID = SUBSTR ($Read, 17, LEN($Read))
$x2=$x2+1
CASE INSTR ($Read, "Processor list:")
$Read = READLINE (2)
$Proc1 = SUBSTR ($Read, 4, LEN($Read))
$Read = READLINE (2)
SELECT
CASE (SUBSTR ($Read, 4, 1) = "1")
$Proc2 = SUBSTR ($Read, 4, LEN($Read))
$Read = READLINE (2)
CASE (SUBSTR ($Read, 4, 1) <> "1")
$Proc2 = ""
ENDSELECT
SELECT
CASE (SUBSTR ($Read, 4, 1) = "2")
$Proc3 = SUBSTR ($Read, 4, LEN($Read))
$Read = READLINE (2)
CASE (SUBSTR ($Read, 4, 1) <> "2")
$Proc3 = ""
ENDSELECT
SELECT
CASE (SUBSTR ($Read, 4, 1) = "3")
$Proc4 = SUBSTR ($Read, 4, LEN($Read))
$Read = READLINE (2)
CASE (SUBSTR ($Read, 4, 1) <> "3")
$Proc4 = ""
ENDSELECT
$x2=$x2+1
CASE INSTR ($Read, "Services Report")
$Read = READLINE (2)
$x3=1
DO
$Read = READLINE (2)
$Stop = SUBSTR ($Read, LEN ($Read), 1)
SELECT
CASE ($Stop = ")")
$Svc = $Read
$x3=$x3+1
$Console = WRITELINE (8, "$SysNam|$Role|$Ver|$Svc" + $CR)
CASE ($Stop <> ")")
GOTO EXIT_SVC
ENDSELECT
UNTIL ($x3=100)
:EXIT_SVC
$x2=$x2+1
CASE INSTR ($Read, "Network Report")
$Read = READLINE (2)
$Read = READLINE (2)
$Read = READLINE (2)
$Domain = SUBSTR ($Read, 22, LEN ($Read))
$x2=$x2+1
CASE INSTR ($Read, "Shared resources at")
$Read = READLINE (2)
$Read = READLINE (2)
$Read = READLINE (2)
$Comment = $Read
$Read = READLINE (2)
$Read = READLINE (2)
$Read = READLINE (2)
$Read = READLINE (2)
$Read = READLINE (2)
$x3=1
DO
$Read = READLINE (2)
SELECT
CASE INSTR ($Read, "The command completed")
GOTO EXIT_SHR
CASE (1)
$Shr = RTRIM ($Read)
$Console = WRITELINE (9, "$SysNam|$Domain|$Role|$Ver|$Shr" + $CR)
$x3=$x3+1
ENDSELECT
UNTIL ($x3=200)
:EXIT_SHR
$x2=$x2+1
ENDSELECT
LOOP
$Console = CLOSE (2)
ENDSELECT
$Console = WRITELINE (7, "$SysNam|$Domain|$Role|$Ver|$SvcPk|$Proc1|$Proc2|$Comment|$ID" + $CR)
GOTO FILE_LOOP
:EXIT_LOOP
$Console = CLOSE (1)
$Console = CLOSE (7)
$Console = CLOSE (8)
$Console = CLOSE (9)