我的VBScript脚本中存在类型不匹配的问题。我知道价值是正确的,但不确定它为什么会出现。
这是脚本终止的行:
WScript.Echo "DNS Server Search Order: " & objNicItem.DNSServerSearchOrder
该脚本需要一个名为servers.txt
的文件(其中包含服务器列表,我正在使用自己的工作站名称进行测试)。
如果我执行error on resume next
脚本有效。但是,如果填充了服务器列表。它显示的信息与每个主机再次有效的fisrt相同,所以它不正确。
'Input from the command line
If Wscript.Arguments.Count = 0 Then
Wscript.Echo "Usage: DNSAudit.vbs servers.txt "
Wscript.Quit
End If
'Input from txt file
Const ForReading = 1
Set objArgs = WScript.Arguments
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(ObjArgs(0), ForReading)
i = 0
Do Until objTextFile.AtEndOfStream
StrNextLine = objTextFile.ReadLine
objDictionary.Add i, StrNextLine
i = i + 1
Loop
For Each objItem In objDictionary
Computer = objDictionary.Item(objItem)
'For Each Computer In Wscript.Arguments
'remote connection to another computer other than using variables
'Set ObjWMIService = GetObject("Winmgmts://COMPUTERNAME") for remote connection
Set ObjWMIService = GetObject("Winmgmts:{impersonationLevel=impersonate}!\\" & Computer & "\root\cimv2")
'If Err.Number <> 0 Then
'WScript.Echo "**************************************************************" & vbCrLf
'WScript.Echo "Connection Errors" & vbCrLf
'WScript.Echo Computer & " " & Err.Description
'WScript.Echo Computer & " " & Err.Description & " investigation required!"
'WScript.Echo "**************************************************************" & vbCrLf
''*********************************************************************************************************
'End if
WScript.Echo "**************************************************************" & vbCrLf
WScript.Echo "Starting Audit on " & computer
WScript.Echo "**************************************************************" & vbCrLf
WScript.Echo "**************************************************************" & vbCrLf
wscript.echo "List DHCP, DNS, WINS Adapter Parameters"
wscript.Echo "**************************************************************" & vbCrLf
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration")
For Each objNicItem in colItems
Wscript.Echo "DHCP Enabled: " & objNicItem.DHCPEnabled
Wscript.Echo "DHCP Lease Expires: " & objNicItem.DHCPLeaseExpires
Wscript.Echo "DHCP Lease Obtained: " & objNicItem.DHCPLeaseObtained
Wscript.Echo "DHCP Server: " & objNicItem.DHCPServer
Wscript.Echo "DNS Domain: " & objNicItem.DNSDomain
Wscript.Echo "DNS Domain Suffix Search Order: " & _
objNicItem.DNSDomainSuffixSearchOrder
Wscript.Echo "DNS Enabled For WINS Resolution: " & _
objNicItem.DNSEnabledForWINSResolution
Wscript.Echo "DNS Host Name: " & objNicItem.DNSHostName
WScript.Echo "DNS Server Search Order: " & objNicItem.DNSServerSearchOrder
WScript.Echo "Domain DNS Registration Enabled: " & objNicItem.DomainDNSRegistrationEnabled
Wscript.Echo "Full DNS Registration Enabled: " & _
objNicItem.FullDNSRegistrationEnabled
Wscript.Echo "IP Address: " & objNicItem.IPAddress
Wscript.Echo "MAC Address: " & objNicItem.MACAddress
Wscript.Echo "TCP Maximum Data Retransmissions: " & _
objNicItem.TcpMaxDataRetransmissions
Wscript.Echo "TCP NumC onnections: " & objNicItem.TcpNumConnections
Wscript.Echo "WINS Host Lookup File: " & objNicItem.WINSHostLookupFile
Wscript.Echo "WINS Primary Server: " & objNicItem.WINSPrimaryServer
Wscript.Echo "WINS Secondary Server: " & objNicItem.WINSSecondaryServer & vbCrLf
Wscript.Echo "Adaptor: " & objNicItem.Description & vbCrLf
Next
Next
答案 0 :(得分:4)
问题是DNSServerSearchOrder是键/值对的列表,因此Echo命令将失败。您将需要枚举所有值,如下所示:
If Not IsNull(objNicItem.DNSServerSearchOrder) Then
For x = 0 To UBound(objNicItem.DNSServerSearchOrder)
WScript.Echo " " & objNicItem.DNSServerSearchOrder(x)
Next
End If
答案 1 :(得分:3)
Win32_NetworkAdapterConfiguration
对象的DNSServerSearchOrder
属性是一个数组,而不是可以(隐式)转换为字符串的值。
答案 2 :(得分:0)
现在使用以下代码完全正常工作:
Wscript.Echo "IP Address: " & objNicItem.IPAddress(0)
谢谢大家