vbscript - AD Query “the remote server does not exist or is unavailable” -


what great idea. redid script suggestion. has problem. new script returns last computer in computer ou. how correctly pass each instance dictionary if statement?

 dim strcomputer, objfiletowrite, objwmiservice   if reachable(queryad)  set objfiletowrite =  createobject("scripting.filesystemobject").opentextfile("\\cheeng.net\winc\it\nuancekey.txt",8,true)  set objwmiservice = getobject("winmgmts:" _ & "{impersonationlevel=impersonate}!\\" & queryad & "\root\cimv2") set colcomputer = objwmiservice.execquery _ ("select * win32_computersystem") each objcomputer in colcomputer     objfiletowrite.write vbnewline & "user name = " & objcomputer.username _         & vbnewline & "computer name = " & objcomputer.name next   wscript.echo  queryad & " computer reachable!" else  wscript.echo queryad & "computer unreachable!"  end if    function queryad  dim objdictionary, stritem, colitems, i, s set objdictionary = createobject("scripting.dictionary") set objou = getobject("ldap://ou=computers,ou=winc,dc=cheeng,dc=net") objou.filter = array("computer")  each objcomputer in objou    ' add workstations dictionary     objdictionary.add a, objcomputer.cn     = + 1  colitems = objdictionary.items  ' workstations.  = 0 objdictionary.count -1 ' iterate array.     s = colitems(i) ' create return string.  next queryad = s  next end function    function reachable(strcomputer) 'test connectivty computer dim wmiquery, objwmiservice, objstatus  ' define wmi query wmiquery = "select * win32_pingstatus address = '" & strcomputer & "'"  ' run wmi query set objwmiservice = getobject("winmgmts:\\.\root\cimv2").execquery(wmiquery)  ' translate query results either true or false each objstatus in objwmiservice if isnull(objstatus.statuscode) or objstatus.statuscode<>0     reachable = false 'if computer unreachable, return false else     reachable = true 'if computer reachable, return true end if next  set objwmiservice = nothing end function 

before connect remote computer, need ping see if it's online. here's function that.

function reachable(strcomputer) 'test connectivty computer dim wmiquery, objwmiservice, objping, objstatus wmiquery = "select * win32_pingstatus address = '" & strcomputer & "'" set objwmiservice = getobject("winmgmts:\\.\root\cimv2") set objping = objwmiservice.execquery(wmiquery) each objstatus in objping     if isnull(objstatus.statuscode) or objstatus.statuscode<>0         reachable = false 'if computer unreachable, return false     else         reachable = true 'if computer reachable, return true     end if next end function 

then use function can

if reachable("computername")     set objwmiservice = getobject...etc 

edit:

you'll want add reachable function inside loop , send 1 computer @ time function.

you might want query ad computers active. example:

set objfiletowrite =  createobject("scripting.filesystemobject").opentextfile("\\cheeng.net\winc\it\nuancekey.txt",8,true)  arrcomps = queryad  each strcomputer in arrcomps  if reachable(strcomputer)      wscript.echo strcomputer & " computer reachable!"     set objwmiservice = getobject("winmgmts:" _         & "{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2")     set colcomputer = objwmiservice.execquery _         ("select * win32_computersystem")     each objcomputer in colcomputer         objfiletowrite.write vbnewline & "user name = " & objcomputer.username _         & vbnewline & "computer name = " & objcomputer.name         'you use strcomputer here instead of objcomputer.name else 'if not reachable     wscript.echo strcomputer & " computer unreachable!" end if 'end reachable if  next  'loop next computer  function queryad     const ads_scope_subtree = 2     dim objdictionary, colitems, strcomputer     set objdictionary = createobject("scripting.dictionary")      set objrootdse = getobject("ldap://rootdse")     strdomain = objrootdse.get("defaultnamingcontext")      set objconnection = createobject("adodb.connection")     set objcommand =   createobject("adodb.command")     objconnection.provider = "adsdsoobject"     objconnection.open "active directory provider"      set objcommand.activeconnection = objconnection     objcommand.commandtext = _         "select name 'ldap://" & strdomain & "' " _         & "where objectclass='computer' , useraccountcontrol <> 4098 , useraccountcontrol <> 4130"     'this computers except disabled computers ad     objcommand.properties("page size") = 1000     objcommand.properties("searchscope") = ads_scope_subtree      set objrecordset = objcommand.execute     objrecordset.movefirst      until objrecordset.eof         strcomputer = objrecordset.fields("name").value         objdictionary.add strcomputer,strcomputer         objrecordset.movenext     loop     objrecordset.close     queryad = objdictionary.items end function   function reachable(strcomputer) 'test connectivty computer     'keep same had end function 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -