#121466 - 2004-06-17 09:13 PM
WriteLine with Variables
|
Mike72677
Fresh Scripter
Registered: 2004-06-17
Posts: 32
Loc: PA
|
I'm working on a script that uses ENUMKEY to list the values of the subkeys that are Microsoft Patches. I'm trying to get the script to take each $KEYNAME and write it to a comma delimited file starting with the $SRVNAME. What's the easiest way to do this? I know I could do it with a write line and name a section for each server, but that can't be sorted easily. Any help? Thanks!!
OPEN (1,"C:\PROGRAM FILES\KIXTART\NASERVERS.TXT",2)
:NextServer
$SRVNAME = ReadLine(1) IF $SRVNAME = "" Goto ENDOFFILE Endif
$Index1 = 0 :LOOP1 $KeyName=EnumKey("\\$SRVNAME\HKLM\Software\Microsoft\Updates\Windows
2000\SP4",$Index1) ? "$KeyName"
IF @ERROR = 0 $Index1 = $Index1 + 1 GOTO LOOP1 ENDIF
$Index2 = 0 :LOOP2 $KeyName=EnumKey("\\$SRVNAME\HKLM\Software\Microsoft\Updates\Windows
2000\SP5",$Index2) ? "$KeyName" IF @ERROR = 0 $Index2 = $Index2 + 1 GOTO LOOP2 ENDIF
GOTO NextServer
:ENDOFFILE
|
|
Top
|
|
|
|
#121468 - 2004-06-17 09:18 PM
Re: WriteLine with Variables
|
Mike72677
Fresh Scripter
Registered: 2004-06-17
Posts: 32
Loc: PA
|
Just a little more info: NASERVER.TXT is just a text file with a list of server names for the script to use.
I'd like to have an output file that is comma delimited, but not sure how to get one long string before issueing the return command.
Ex. WriteLine( 2 , '"Server Name","$Keyname","$Keyname2","$Keyname3","$Keyname4", "$Keyname5"' + Chr(13) + Chr(10) )
I can't really number the $KeyName variables, because they're might not always be the same number of them. Thanks!
|
|
Top
|
|
|
|
#121469 - 2004-06-17 09:19 PM
Re: WriteLine with Variables
|
Mike72677
Fresh Scripter
Registered: 2004-06-17
Posts: 32
Loc: PA
|
One file with a line for each server.
|
|
Top
|
|
|
|
#121470 - 2004-06-17 10:07 PM
Re: WriteLine with Variables
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Heres kind of an over-wrought start, change $input to be your input file and $output to be your new output file, change the $w2k3 variable depending and then add more keys for other OS's ... would even be cool to dynamically enum the higher level keys use a table of SP's for your search, anyway:
Code:
break on
$input = ".\input.txt"
$output = ".\output.txt"
$W2K3 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows Server 2003\sp1"
if open(1,$input) = 0
if exist($output)
del "$output"
endif
if open(2,$output,5) = 0
$server = readline(1)
while $server
$str = $server
$i = 0
$key = enumkey("\\$server\"+$w2K3,$i)
while $key
$str = $str + "," + $key
$i=$i+1
$key = enumkey("\\$server\"+$w2K3,$i)
loop
$= writeline(2,$str+@CRLF)
$server = readline(1)
loop
$= close(2)
endif
$=close(1)
endif
exit 1
Copy this code into wordpad and then copy/paste into notepad to get proper formatting, hope this helps.
-Shawn
|
|
Top
|
|
|
|
#121471 - 2004-06-17 10:18 PM
Re: WriteLine with Variables
|
Mike72677
Fresh Scripter
Registered: 2004-06-17
Posts: 32
Loc: PA
|
Thanks for all your help! Finally had a brain storm and figured something out! WriteLine doesn't automatically append a carriage return. So I can just keep using $Keyname, in my writeline statements then when I'm done reading keys for that server, I end with a writeline that is just a carriage return! And I just start with a writeline with $SRVName,. Thanks for your quick replies!
WriteLine( 2,"$SRVName,") WriteLine( 2,"$KeyName,") WriteLine( 2 ,Chr(13) + Chr(10) )
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 271 anonymous users online.
|
|
|