none
Scrip de coleta de dados. RRS feed

  • Pergunta

  • Bom dia, estou criando um scrip para colher informações em uma rede, e dando formato a ele para que fique mais facil a visualização,

    Const ADS_SCOPE_SUBTREE = 2
    Const ForAppending = 8


    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile ("result.xls", ForAppending, True)
    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, Location from 'LDAP://DC=,DC=' " _
             & "Where objectClass='computer'"
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

     

    objTextFile.WriteLine "<center><table border='1' bgcolor='#8B8989'>"

    objTextFile.WriteLine "<tr>"


    objTextFile.WriteLine " <td width='220' align='center'><b>Computadores:</td></b>" & "<td width='220' align='center'><b> Usuario:</b></td> <br>"
    objTextFile.WriteLine "</tr>"
    objTextFile.WriteLine "</table>"

    Set objRecordSet = objCommand.Execute
    objRecordSet.MoveFirst
    Wscript.Echo "Iniciando a Coleta"
    on error resume next
    Do Until objRecordSet.EOF
     strComputer = objRecordSet.Fields("Name").Value
     Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

      if err.number=0 then
      Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")

       For Each objComputer in colComputer
       
                
       objTextFile.WriteLine "<table border='1'>"
       objTextFile.WriteLine "<tr>"
       objTextFile.WriteLine  "<center><td width='220'>"&"" & objRecordSet.Fields("Name").Value &"</td>"& "<td width='220'>" & objComputer.UserName & "</td>"
       objTextFile.WriteLine "</tr>"
       objTextFile.WriteLine "</table>"

       
      Next  
     else
      
       objTextFile.WriteLine "<table border='1'>"
       objTextFile.WriteLine "<tr>"
       objTextFile.WriteLine  "<center><td width='220'>" & objRecordSet.Fields("Name").Value &"</td>"& "<td width='220'>" & "<font color='red'>Usuario Desconectado" & "</td>"
       objTextFile.WriteLine "</tr>"
       objTextFile.WriteLine "</table>"
      
      err.clear
     end if
     
        objRecordSet.MoveNext
     Loop
     
     Wscript.Echo "Coleta Concluída , verifique o arquivo result.html"
     objTextFile.Close

    Gostaria de saber se alguém saberia como faço para ELE EXIBIR a data que a informação foi tirada junto com as outras informações e se é possivel organizar as informações em ordem alfabetica...Se alguém poder me ajudar fico muito agradecido...Obrigado.

    sexta-feira, 25 de maio de 2012 12:17

Respostas

  • Cara acrescente duas linhas no seu script:

    Abaixo de:

    objTextFile.WriteLine "<center><table border='1' bgcolor='#8B8989'>"


    Coloque:

    objTextFile.WriteLine " <tr><td colspan='2' width='220' align='center'><b>Lista gerada em "& now()  &" </td></b></tr>"

    Abaixo de:

    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE


    Coloque:

    objCommand.Properties("Sort On") = "Name" 

    Tudo junto fica assim:

    Const ADS_SCOPE_SUBTREE = 2
     Const ForAppending = 8
     
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
     Set objTextFile = objFSO.OpenTextFile ("result.xls", ForAppending, True)
     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, Location from 'LDAP://DC=,DC=' " _
              & "Where objectClass='computer'" 
    objCommand.Properties("Page Size") = 1000
     objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
     objCommand.Properties("Sort On") = "Name" 
     
     
     
    objTextFile.WriteLine "<center><table border='1' bgcolor='#8B8989'>"
     objTextFile.WriteLine " <tr><td colspan='2' width='220' align='center'><b>Lista gerada em "& now()  &" </td></b></tr>"
    objTextFile.WriteLine "<tr>"
     
    
    objTextFile.WriteLine " <td width='220' align='center'><b>Computadores:</td></b>" & "<td width='220' align='center'><b> Usuario:</b></td> <br>"
     objTextFile.WriteLine "</tr>"
     objTextFile.WriteLine "</table>"
     
    Set objRecordSet = objCommand.Execute
    	
     objRecordSet.MoveFirst
     Wscript.Echo "Iniciando a Coleta"
     on error resume next
     Do Until objRecordSet.EOF
      strComputer = objRecordSet.Fields("Name").Value
      Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
      if err.number=0 then
       Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
     
       For Each objComputer in colComputer
        
                 
        objTextFile.WriteLine "<table border='1'>"
        objTextFile.WriteLine "<tr>"
        objTextFile.WriteLine  "<center><td width='220'>"&"" & objRecordSet.Fields("Name").Value &"</td>"& "<td width='220'>" & objComputer.UserName & "</td>"
        objTextFile.WriteLine "</tr>"
        objTextFile.WriteLine "</table>"
     
       
       Next   
     else
       
        objTextFile.WriteLine "<table border='1'>"
        objTextFile.WriteLine "<tr>"
        objTextFile.WriteLine  "<center><td width='220'>" & objRecordSet.Fields("Name").Value &"</td>"& "<td width='220'>" & "<font color='red'>Usuario Desconectado" & "</td>"
        objTextFile.WriteLine "</tr>"
        objTextFile.WriteLine "</table>"
       
       err.clear
      end if
      
         objRecordSet.MoveNext
      Loop
      
      Wscript.Echo "Coleta Concluída , verifique o arquivo result.html"
      objTextFile.Close
    

    Favor marcar se útil.

    Até...


    Warley

    • Marcado como Resposta Luanpbi sexta-feira, 25 de maio de 2012 13:47
    sexta-feira, 25 de maio de 2012 13:02

Todas as Respostas

  • Cara acrescente duas linhas no seu script:

    Abaixo de:

    objTextFile.WriteLine "<center><table border='1' bgcolor='#8B8989'>"


    Coloque:

    objTextFile.WriteLine " <tr><td colspan='2' width='220' align='center'><b>Lista gerada em "& now()  &" </td></b></tr>"

    Abaixo de:

    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE


    Coloque:

    objCommand.Properties("Sort On") = "Name" 

    Tudo junto fica assim:

    Const ADS_SCOPE_SUBTREE = 2
     Const ForAppending = 8
     
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
     Set objTextFile = objFSO.OpenTextFile ("result.xls", ForAppending, True)
     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, Location from 'LDAP://DC=,DC=' " _
              & "Where objectClass='computer'" 
    objCommand.Properties("Page Size") = 1000
     objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
     objCommand.Properties("Sort On") = "Name" 
     
     
     
    objTextFile.WriteLine "<center><table border='1' bgcolor='#8B8989'>"
     objTextFile.WriteLine " <tr><td colspan='2' width='220' align='center'><b>Lista gerada em "& now()  &" </td></b></tr>"
    objTextFile.WriteLine "<tr>"
     
    
    objTextFile.WriteLine " <td width='220' align='center'><b>Computadores:</td></b>" & "<td width='220' align='center'><b> Usuario:</b></td> <br>"
     objTextFile.WriteLine "</tr>"
     objTextFile.WriteLine "</table>"
     
    Set objRecordSet = objCommand.Execute
    	
     objRecordSet.MoveFirst
     Wscript.Echo "Iniciando a Coleta"
     on error resume next
     Do Until objRecordSet.EOF
      strComputer = objRecordSet.Fields("Name").Value
      Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
     
      if err.number=0 then
       Set colComputer = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
     
       For Each objComputer in colComputer
        
                 
        objTextFile.WriteLine "<table border='1'>"
        objTextFile.WriteLine "<tr>"
        objTextFile.WriteLine  "<center><td width='220'>"&"" & objRecordSet.Fields("Name").Value &"</td>"& "<td width='220'>" & objComputer.UserName & "</td>"
        objTextFile.WriteLine "</tr>"
        objTextFile.WriteLine "</table>"
     
       
       Next   
     else
       
        objTextFile.WriteLine "<table border='1'>"
        objTextFile.WriteLine "<tr>"
        objTextFile.WriteLine  "<center><td width='220'>" & objRecordSet.Fields("Name").Value &"</td>"& "<td width='220'>" & "<font color='red'>Usuario Desconectado" & "</td>"
        objTextFile.WriteLine "</tr>"
        objTextFile.WriteLine "</table>"
       
       err.clear
      end if
      
         objRecordSet.MoveNext
      Loop
      
      Wscript.Echo "Coleta Concluída , verifique o arquivo result.html"
      objTextFile.Close
    

    Favor marcar se útil.

    Até...


    Warley

    • Marcado como Resposta Luanpbi sexta-feira, 25 de maio de 2012 13:47
    sexta-feira, 25 de maio de 2012 13:02
  • Funciono, Fico SHOW, valeu mesmo.

    sexta-feira, 25 de maio de 2012 13:48