Issue Splitting DNSServerSearchOrder results and sending to SQL DB

Home Forums Scripting Windows Script Host Issue Splitting DNSServerSearchOrder results and sending to SQL DB

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    XIIxOveR
    Member
    #152155

    Hi there,

    Hopefully I can explain this well enough so that it makes sense. I’m relatively new to VBScript which will probably be quite evident in this, my first post here.

    I am trying to capture the value of DNSServerSearchOrder from servers listed in an input file. I then want to write the primary, secondary, and tertiary values out to three seperate columns in a SQL database. Where I’m having trouble is sometimes a server may correctly have all three values whereby sometimes it will only have one or two values.

    Function ReportDnsWins(DeviceName)
    Dim objWMIService, colCards, objCard, strDNSServerSearchOrder, strDNSServers
    Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\” & DeviceName & “rootcimv2”)
    Set colCards = objWMIService.ExecQuery(“Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True”)
    For Each objCard in colCards
    strDNSServerSearchOrder = Join(objCard.DNSServerSearchOrder, “,”)
    strDNSServers = split(strDNSServerSearchOrder, “,”)
    Call Write2DB(DeviceName, strDNSServers(0), strDNSServers(1), strDNSServers(2), objCard.WINSPrimaryServer, objCard.WINSSecondaryServer)
    Next
    End Function
    [/CODE]

    So this works great if the strDNSServers array ends up populated with three values from the split, however this will give an “out of range”, of course, for servers with only one or two values. If it’s anything over three I don’t care, I only care about the first three.

    This also works great if I want to keep it simple and output the entire value of DNSServerSearchOrder to a single column in SQL thus tracking the entire list of DNS servers in the column and sorting the results of the query in Excel or something rather than using the transact SQL query itself. But this seems like it should be simple enough so I can’t let it go!

    Definitely open to any insight, it would take me a bit to explain everything I’ve tried so far but if it helps I’ll try. Hopefully someone can help me think the logic through here, I’m probably missing something simple.

    Thanks!

    X[CODE]
    Function ReportDnsWins(DeviceName)
    Dim objWMIService, colCards, objCard, strDNSServerSearchOrder, strDNSServers
    Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\” & DeviceName & “rootcimv2”)
    Set colCards = objWMIService.ExecQuery(“Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True”)
    For Each objCard in colCards
    strDNSServerSearchOrder = Join(objCard.DNSServerSearchOrder, “,”)
    strDNSServers = split(strDNSServerSearchOrder, “,”)
    Call Write2DB(DeviceName, strDNSServers(0), strDNSServers(1), strDNSServers(2), objCard.WINSPrimaryServer, objCard.WINSSecondaryServer)
    Next
    End Function
    [/CODE]

    So this works great if the strDNSServers array ends up populated with three values from the split, however this will give an “out of range”, of course, for servers with only one or two values. If it’s anything over three I don’t care, I only care about the first three.

    This also works great if I want to keep it simple and output the entire value of DNSServerSearchOrder to a single column in SQL thus tracking the entire list of DNS servers in the column and sorting the results of the query in Excel or something rather than using the transact SQL query itself. But this seems like it should be simple enough so I can’t let it go!

    Definitely open to any insight, it would take me a bit to explain everything I’ve tried so far but if it helps I’ll try. Hopefully someone can help me think the logic through here, I’m probably missing something simple.

    Thanks!

    X

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.