I wrote something like it.
It works, but wscript.echo return 2 message "Something is wrong". Script don't want do process my loop. Anybody know how to do it?
On Error Resume Next
Dim ComputerName
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
strComputer = "."
Set dict = CreateObject("Scripting.Dictionary")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
If Len(objItem.DNSDomain) > 0 And Len(objItem.DNSHostName) Then
dict.Add (objItem.DNSHostName & "." & objItem.DNSDomain), dict.Count
End If
Next
fqdnArray = dict.Keys
For Each fqdn In fqdnArray
if fqdn = "HR-Computers.miami.contoso.com." then
WScript.Echo fqdn
else
wscript.echo "Something is wrong"
end if
can you have more than one network adapter which has a configuration other than HR-Computers.miami.contoso.com?
comment out the On Error Resume Next to clarify if you have any run time errors which are causing issues.
if you have no runtimes, then your script is behaving as you have coded it. if that is the case then i would add some more information gathering so you can see waht you are 'really' returning in your WMI query.
For Each objItem In colItems
If Len(objItem.DNSDomain) > 0 And Len(objItem.DNSHostName) Then
Wscript.Echo "adding to dictionary " & objItem.DNSHostName & "." & objItem.DNSDomain & " dic.count = " & CStr(dict.Count)
dict.Add (objItem.DNSHostName & "." & objItem.DNSDomain), dict.Count
End If
Next
'then later
For Each fqdn In fqdnArray
wscript.echo "will compare " & fqdn & " against " & "HR-Computers.miami.contoso.com."
if fqdn = "HR-Computers.miami.contoso.com." then
WScript.Echo fqdn
else
wscript.echo "Something is wrong"
end if
Next
i guess my real point is that we work in IT, information technology. 'information' is the important part. you have lots of information in your script, but you choose not to share it with yourself. This is your limiting factor
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.