vbscript change from parsing groups to OUs

I've got a vbscript (below) that parses AD groups.  For each member it tries to ping, if successful it tries to connect to the WMI DB, if successful it quieries for NIC properties.  It works very well, but I'm having trouble adapting it to look at an OU (and sub OUs) rather than a group.  

Thanks!

--------------------------------------------------------------------------------
on error resume next
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("D:\Data\Tools\Scripts\WMI-Reports\Reports\AdapterReport3-23-10.csv", ForAppending, True)

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCOmmand.ActiveConnection = objConnection
Set objGroup = GetObject _
      ("LDAP://CN=Comp-All,OU=Groups,DC=ourdomain,DC=domain,DC=com")

strName = objGroup.Get("name")
arrMemberOf = objGroup.GetEx("member")

      objTextFile.WriteLine "Date,Time,Hostname,MAC,IP,Adapter,Driver Version"
      objTextFile.WriteLine Date & "," & TIME & VbCrLf


For Each strMember in arrMemberOf
      strMember = Mid(strMember, 4, 330)
      arrGroup = Split(strMember, "," )

      Set objShell = CreateObject("WScript.Shell")
      Set objScriptExec = objShell.Exec( _
          "ping -n 2 -w 500 " & arrgroup(0))
      strPingResults = LCase(objScriptExec.StdOut.ReadAll)
      If InStr(strPingResults, "reply from") Then
          If InStr(strPingResults, "destination net unreachable") Then
            objTextFile.Write vbcrlf & "," & TIME & "," & arrgroup(0) & "," & "NO RESPONSE"
          Else
            'objTextFile.Write vbcrlf & "," & TIME & "," & arrgroup(0) & "," & "RESPONDED"

            Err.Clear
            Set objWMIService = GetObject("winmgmts:" _
             & "{impersonationLevel=impersonate}!\\" & arrgroup(0) & "\root\cimv2")

            If Err.Number <> 0 Then
                        objTextFile.Write  vbcrlf & "," & TIME & "," & arrgroup(0) & "," & "WMI FAILED"
            Else

                  Set colAdapters = objWMIService.ExecQuery _
                   ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True and DHCPEnabled=False")

                        For Each objAdapter in colAdapters
                            If Not IsNull(objAdapter.IPAddress) Then
                              For i = LBound(objAdapter.IPAddress) To UBound(objAdapter.IPAddress)
                                objTextFile.Write vbcrlf & "," & TIME & "," & arrgroup(0) & "," & objAdapter.MACAddress & "," & objAdapter.IPAddress(i) & "," & objAdapter.Description & "," & GetDriverVersion(objAdapter.Description)
                                'adapter = adapter & objAdapter.Description & vbCrLf & "    MAC address: " & objAdapter.MACAddress & vbCrLf & "    IP Address: " & objAdapter.IPAddress(i) & vbCrLf & "    Driver Version:  " & GetDriverVersion(objAdapter.Description) & vbCrLf & vbCrLf
                              Next
                            End If
                        Next

            End If

          End If
        Else
      objTextFile.Write vbcrlf & "," & TIME & "," & arrgroup(0) & "," & "NO PING RESPONSE"
        End If

Next

objTextFile.WriteLine VBcrlf & Date & "," & TIME
objTextFile.Write VBcrlf


Function GetDriverVersion(myAdapter)

       ON ERROR RESUME NEXT

       Set colDrivers = objWMIService.ExecQuery _
             ("select * from Win32_PnPSignedDriver where DeviceClass='NET'")

       For Each objDriver in colDrivers
             If left(myAdapter,len(objDriver.Description))=objDriver.Description then
                   drv=objDriver.DriverVersion
             End If
       Next

       GetDriverVersion=drv
End Function
--------------------------------------------------------------------------------
mbrombAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi, to go through an OU, you would use the code below to start off the query:

Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT adsPath FROM 'LDAP://OU=SecondOU,OU=FirstOU,dc=My,dc=Domain,dc=com' WHERE objectCategory='user'"
 
Set objRecordSet = objCommand.Execute

objTextFile.WriteLine "Date,Time,Hostname,MAC,IP,Adapter,Driver Version"
objTextFile.WriteLine Date & "," & TIME & VbCrLf


While Not objRecordSet.EOF
strUserPath = objRecordSet("adsPath")
'.........
'.........
objRecordSet.MoveNext
Wend




But it's not clear how you're obtaining strMember and strGroup values, so you will need to have a look at the adspath in strUserPath and see if you can work with that.

Regards,

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mbrombAuthor Commented:
Sorry for the delayed reply.  I was distracted and will have to revisit this to test, but thank you for the info.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.