none
How to import from an array RRS feed

  • Question

  • Hi all,

    OK so I need to import a list of IP addresses (around 96000) which will then do an RPC call and pull the information in the script

    On Error Resume Next
    
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    
    ' Read a Text File into an Array
    
    
    Const ForReading = 1
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile _
        ("c:\scripts\servers.txt", ForReading)
    
    Do Until objTextFile.AtEndOfStream
        strNextLine = objTextFile.Readline
        arrServiceList = Split(strNextLine , ",")
        Wscript.Echo "Computer: " & arrServiceList(0)
        For i = 1 to Ubound(arrServiceList)
            Wscript.Echo "Service: " & arrServiceList(i)
        Next
    Loop
    
    For Each strComputer In arrComputers
       WScript.Echo
       WScript.Echo "=========================================="
       WScript.Echo "Computer: " & strComputer
       WScript.Echo "=========================================="
    
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
       Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
                                              wbemFlagReturnImmediately + wbemFlagForwardOnly)
    
       For Each objItem In colItems
          WScript.Echo "DNSHostName: " & objItem.DNSHostName
          WScript.Echo "Domain: " & objItem.Domain
          WScript.Echo "DomainRole: " & objItem.DomainRole     
    	  WScript.Echo "Manufacturer: " & objItem.Manufacturer
          WScript.Echo "Model: " & objItem.Model
          WScript.Echo "Name: " & objItem.Name
          WScript.Echo "NameFormat: " & objItem.NameFormat
          WScript.Echo "NetworkServerModeEnabled: " & objItem.NetworkServerModeEnabled
          WScript.Echo "PowerOnPasswordStatus: " & objItem.PowerOnPasswordStatus
          WScript.Echo "ResetCount: " & objItem.ResetCount
          WScript.Echo "ResetLimit: " & objItem.ResetLimit
          WScript.Echo
       Next
    Next
    
    
    Function WMIDateStringToDate(dtmDate)
    WScript.Echo dtm: 
    	WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
    	Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
    	& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
    End Function
    

    I'm not very good at this, can someone explain why the above doesn't work?

    Thanks

    Alex

    Thursday, December 4, 2014 12:10 PM

Answers

  • powershell equivlent

    Get-Content servers.txt | %{gwmi win32_computersystem -cn $_}|Format-List


    ¯\_(ツ)_/¯

    • Marked as answer by Alexgreen312 Thursday, December 4, 2014 12:47 PM
    Thursday, December 4, 2014 12:38 PM

All replies

  • "Learn Powershell, or learn that the round ones are burgers and the square ones are fish."

      -Jeffrey Snover


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    Thursday, December 4, 2014 12:31 PM
    Moderator
  • Here are some hotdogs to go with you burgers:

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile("c:\scripts\servers.txt")
    
    Do Until objTextFile.AtEndOfStream
        strComputer=objTextFile.Readline()
        WScript.Echo "GEtting computer:" & strComputer
       	Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
      	Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem")
    	For Each objItem In colItems
    		WScript.Echo "DNSHostName: " & objItem.DNSHostName
    		WScript.Echo "Domain: " & objItem.Domain
    		WScript.Echo "DomainRole: " & objItem.DomainRole     
    		WScript.Echo "Manufacturer: " & objItem.Manufacturer
    		WScript.Echo "Model: " & objItem.Model
    		WScript.Echo "Name: " & objItem.Name
    		WScript.Echo "NameFormat: " & objItem.NameFormat
    		WScript.Echo "NetworkServerModeEnabled: " & objItem.NetworkServerModeEnabled
    		WScript.Echo "PowerOnPasswordStatus: " & objItem.PowerOnPasswordStatus
    		WScript.Echo "ResetCount: " & objItem.ResetCount
    		WScripho
    	Next
    Next
    
    

    Of course you have to have the corrrect file and you need to not copy broken code.


    ¯\_(ツ)_/¯

    Thursday, December 4, 2014 12:37 PM
  • powershell equivlent

    Get-Content servers.txt | %{gwmi win32_computersystem -cn $_}|Format-List


    ¯\_(ツ)_/¯

    • Marked as answer by Alexgreen312 Thursday, December 4, 2014 12:47 PM
    Thursday, December 4, 2014 12:38 PM
  • You Have Three problem Missing a "'" at the end of 

    1: 'Read a Text File into Array

        'Read a Text File into Array'

    2:       strNextLine =objTextFile.Readline    should be

              strComputer =objTextFile.Readline

    3:           arrServiceList = Split(strNextLine ,",")     should be

          arrServiceList = Split(strComputer ,",")

    I fixed the script below

    On Error Resume Next
    
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    
    ' Read a Text File into an Array'
    
    
    Const ForReading = 1
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile _
        ("c:\scripts\servers.txt", ForReading)
    
    Do Until objTextFile.AtEndOfStream
        strComputer = objTextFile.Readline
        arrServiceList = Split(strComputer , ",")
        Wscript.Echo "Computer: " & arrServiceList(0)
        For i = 1 to Ubound(arrServiceList)
            Wscript.Echo "Service: " & arrServiceList(i)
        Next
    Loop
    
    For Each strComputer In arrComputers
       WScript.Echo
       WScript.Echo "=========================================="
       WScript.Echo "Computer: " & strComputer
       WScript.Echo "=========================================="
    
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
       Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem", "WQL", _
                                              wbemFlagReturnImmediately + wbemFlagForwardOnly)
    
       For Each objItem In colItems
          WScript.Echo "DNSHostName: " & objItem.DNSHostName
          WScript.Echo "Domain: " & objItem.Domain
          WScript.Echo "DomainRole: " & objItem.DomainRole     
    	  WScript.Echo "Manufacturer: " & objItem.Manufacturer
          WScript.Echo "Model: " & objItem.Model
          WScript.Echo "Name: " & objItem.Name
          WScript.Echo "NameFormat: " & objItem.NameFormat
          WScript.Echo "NetworkServerModeEnabled: " & objItem.NetworkServerModeEnabled
          WScript.Echo "PowerOnPasswordStatus: " & objItem.PowerOnPasswordStatus
          WScript.Echo "ResetCount: " & objItem.ResetCount
          WScript.Echo "ResetLimit: " & objItem.ResetLimit
          WScript.Echo
       Next
    Next
    
    
    Function WMIDateStringToDate(dtmDate)
    WScript.Echo dtm: 
    	WMIDateStringToDate = CDate(Mid(dtmDate, 5, 2) & "/" & _
    	Mid(dtmDate, 7, 2) & "/" & Left(dtmDate, 4) _
    	& " " & Mid (dtmDate, 9, 2) & ":" & Mid(dtmDate, 11, 2) & ":" & Mid(dtmDate,13, 2))
    End Function


    • Edited by Devlinsd Thursday, December 4, 2014 12:46 PM
    • Proposed as answer by Devlinsd Thursday, December 4, 2014 12:47 PM
    Thursday, December 4, 2014 12:45 PM
  • why didn't I think of powershell... I'm an idiot..

    Thanks :D

    Thursday, December 4, 2014 12:47 PM