1

want to write a Vb Script to get the full information on all the host name, and ip address and sub net mask of computer that has been added to the domain control.

jason
  • 43
  • 1
  • 1
  • 5
  • Your 'question' goes a bit beyond the scope of what can be reasonable answered. Also there are many existing tools which can do this. Most people will not write this for you. If still want to write it yourself you may want to start working on it and post specific questions about what you are having problems doing on stackoverflow. – Zoredache May 03 '10 at 22:15

2 Answers2

2

Your best bet is to check out the microsoft script center where much of that has been written for you. The script center has tutorials as well as the script repository where windows admins share scripts. You should also take a look at the scriptomatic, an HTA application that can generate wmi reader code for you

Jim B
  • 24,081
  • 4
  • 36
  • 60
2

Here is a VBS script, adapted from this page (look for "list Domain, computer and IP of all computers in AD"):

' Modify these vars to match your enviroment
' requires Windows 2003 DNS

strDomain = "MyWindowsDomain"     ' Windows Domain NetBIOS Name
strDNSSVR = "DNSserver"           ' DNS Server's name or IP
strDNSDomain = ".mydomain.com"    ' Note the . at the beginning!
strFILENAME = "AD-Computers.txt"   ' Output File Name

'------------------------------------------------
'
' File stuff
Dim filesys, testfile 
Set filesys = CreateObject("Scripting.FileSystemObject") 
Set OUTfile= filesys.CreateTextFile(strFILENAME, 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
objCommand.CommandText = _
    "Select Name, Location from 'LDAP://" & strDomain & "' " _
        & "Where objectCategory='computer'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst



'debug stuff   Comment if you want to see it during execution
'Wscript.Echo "My DNS Server is: " & strDNSSVR
'Wscript.Echo "My Windows Domain is: " & strDomain
'Wscript.Echo "My DNS Suffix is: " & strDNSDomain
'Wscript.echo "Writing output to File: " & strFILENAME

'output
Do Until objRecordSet.EOF
    strHOST = objRecordSet.Fields("Name").Value
    strHOSTFQDN = strHOST & strDNSDomain
    strIP = GetIPFromDNS(strHOSTFQDN,strDNSSVR)
    OUTfile.WriteLine strDomain & " " & strHOST & " " & strIP
    'Comment line below to not dump output to screen
    Wscript.Echo strDomain & " " & strHOST & " " & strIP
     objRecordSet.MoveNext
Loop

Function GetIPFromDNS(sFQDN, strDNS)
  Set objWMI=GetObject("WinMgmts://" & strDNS & "\root\microsoftDNS")    
  Set colIP=objWMI.ExecQuery("Select * from MicrosoftDNS_AType where ownerName='" & sFQDN & "'")     
    For Each item In colIP          
        GetIPFromDNS = item.RecordData     
    Next
End Function

Outfile.Close 
splattne
  • 28,508
  • 20
  • 98
  • 148