vbscript question (1 Viewer)

token_remedie

Registered User.
Local time
Today, 14:47
Joined
Jul 7, 2011
Messages
78
this loop isn't working:

Code:
for each ServerName in ServerList
    
    wscript.echo ServerName
q = """"

if rs.eof <> true and rs.bof <> true then 

     objcsv.writeline(q & rs("name") & q & "," &  q & rs("operatingsystem") & q & _
        "," & q & rs("operatingsystemservicepack") & _
        q & "," & q & rs("operatingsystemversion") &_
        q & "," & q & rs("distinguishedname") & q)
     rs.movenext

else 
end if

next

it just cycles right through the servername's and doesn't do anything else. I've also tried a while inside the for loop. that just looped forever as far as I can tell.

is there a better way if doing this?
 

token_remedie

Registered User.
Local time
Today, 14:47
Joined
Jul 7, 2011
Messages
78
good point. It populates the csv file but no data in it. here is the full code:

Code:
' Where are all the girls? You said there'd be girls
dim cmd, cn, rs, objRoot, objFSO, objCSV, q

const FileName ="domaincomputers2.csv"
set cmd = createobject("ADODB.Command")
set cn = createobject("ADODB.Connection")
set rs = createobject("ADODB.Recordset")


cn.open "Provider=ADsDSOObject;"
cmd.activeconnection = cn
'******ERROR**************
On Error resume next
 if Err.Number <> 0 then 
        'an exception occurred
                  MsgBox "Error: " & Err.Description
                  end if 
'******HANDLER************


'server array 
    ServerList = array("domain1.com","domain2.com","domain3.com","domain4.com")



' Get RootDSE name
    Set root = GetObject("LDAP://" & ServerName & "/RootDSE")
    'sDomain = objRootDSE.Get("defaultNamingContext")
    Set domain = GetObject("LDAP://" & ServerName &  "/" & sDomain)

'defaultNamingContext
cmd.commandtext = "<LDAP://" & objRoot.get("defaultNamingContext") & ">;(objectCategory=Computers);" & _
          "name,operatingsystem,operatingsystemservicepack,distinguishedname,operatingsystemversion;subtree"
'**** Bypass 1000 record limitation ****
cmd.properties("page size")=10000



title = "Did you bring your own beer?"

msgbox("mainloopstart")

'------------ Start Main Loop -----------------
    
set rs = cmd.EXECUTE
set objFSO = CREATEOBJECT("Scripting.FileSystemObject")
set objCSV = objFSO.createtextfile(FileName)

    
    
for each ServerName in ServerList
    
    wscript.echo ServerName
q = """"

if rs.eof <> true and rs.bof <> true then 

     objcsv.writeline(q & rs("name") & q & "," &  q & rs("operatingsystem") & q & _
        "," & q & rs("operatingsystemservicepack") & _
        q & "," & q & rs("operatingsystemversion") &_
        q & "," & q & rs("distinguishedname") & q)
     rs.movenext

else 
end if

next
    
    

objCSV.Close
cn.close
    msgbox("end")



  strSoundFile = "C:\Windows\Media\Notify.wav"
Set objShell = CreateObject("Wscript.Shell")
strCommand = "sndrec32 /play /close " & chr(34) & strSoundFile & chr(34)
objShell.Run strCommand, 0, True
 

spikepl

Eledittingent Beliped
Local time
Today, 06:47
Joined
Nov 3, 2010
Messages
6,142
I don't know what debugging facilities are available for vbscript, but the debugging, one way or the other, always entails verifying all the assumptions, by checking what data values you have and where, and if you have the right data, whether the logic follows the intended path.
 

Users who are viewing this thread

Top Bottom