Advertisement

[x]
Attachment Details

VBScript to ping machines and check domain membership

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2
OK I created the following script - it basically reads a list of computer names line by line from a text file  pings them to see if they are on the network and returns an IP address and outputs the results to a text file :

Dim objShell, strComputer, strInput
Dim strPing

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\computerlist.txt", ForReading)

Const ForReading = 1
Const ForAppending = 8

Dim arrFileLines()
i = 0
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close

Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.FileExists("c:\output.txt") Then

Else
   Set objFile = objFSO.CreateTextFile("c:\output.txt")
End If

set objFile = nothing

Set objFile = objFSO.OpenTextFile("c:\output.txt", ForAppending)

For Each strLine in arrFileLines
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
        ExecQuery("select * from Win32_PingStatus where address = '"_
            & strLine & "'")
    For Each objStatus in objPing
        If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
            objFile.WriteLine("Computer " & strLine & " is not reachable" & vbTab & objStatus.ProtocolAddress)
        Else
            objFile.WriteLine("Computer " & strLine & " is reachable *********************"& vbTab & objStatus.ProtocolAddress)
        End If
    Next
Next
objFile.Close

***This all works fine!

Now what I want to do is check the domain membership of the pcs that are found to be on the network. I have found a mini script that queries a given pc for its domain membership:

sNode = "computername"

Set colComputer = GetObject("winmgmts:\\" & sNode & "\root\cimv2").ExecQuery("Select DomainRole, Domain from Win32_ComputerSystem")
For Each oComputer in colComputer
iDR = oComputer.DomainRole
sName = oComputer.Domain
Next

If iDR = 0 Or iDR = 2 Then
WScript.Echo "Computer is in workgroup " & sName
Else
WScript.Echo "Computer is in domain " & sName
End If

This script by itself works fine. What I want to do is tie them together do the original script returns the list of IP address, the fact it is online and its domain membership(if it is in the domain)

Can someone do this for me - I know its simple but im not a great scripter and its giving me nightmares.....
Related Solutions
Related Solutions
 
Loading Advertisement...
 
Accepted Solution by gecko_au2003:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Expert Comment by gecko_au2003:

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
Loading Advertisement...
20080924-EE-VQP-41 / EE_QW_2_20070628