Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Need to fix the bug in below script

$
0
0

Hi,

I have a script which used to get the information of the hostname and ipaddress. But it is not working for me. Can anyone help me to fix the bug in this script.In this script I have given the IP of my dns and as per the script it should fetch the hostname and IP address of the server , where all below Preferred/alternate DNS IP has given.


strDomain = "a.b.com"    ' Windows Domain NetBIOS Name
strDNSSVR = "10.0.0.1"   ' DNS Server's IP
str1DNSSVR = "10.0.0.2"   ' DNS Server's IP
strDNSDomain = ".a.b.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 


Viewing all articles
Browse latest Browse all 15028

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>