The function below seems to work on 90% of windows servers. It catches if the server is a DC or not. But for some reason it hangs on some boxes. What would my next step be? It doesnt get to the msgbox that says "Im in the loop".
Any help please!
Any help please!
Code:
'DomainControllerCheck - If the server is a DC then skip it. Otherwise the domain admin account
'has its password reset.
Function DomainContollerCheck(strComputername)
Dim objWMIService, colComputers, colItem
'==========================================
'Call the WMI service on the target machine
'==========================================
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputername & "\root\cimv2")
'==========================================================
'Extract the contents of the Win32_ComputerSystem container
'==========================================================
Set colComputers = objWMIService.ExecQuery _
("Select DomainRole from Win32_ComputerSystem")
'=========================================================
'Loop through the results as it is passed back as an array
'=========================================================
for each colItem in colComputers
msgbox "im in the loop"
if colItem.DomainRole = 4 or colItem.DomainRole = 5 then
'========================================================================
'If the computer is a domain controller, this part of the script executes
'========================================================================
msgbox "This is a domain controller"
dc = 1
else
'==================================================================
'If the computer is anything else, this part of the script executes
'==================================================================
msgbox "This is not a domain controller"
dc = 0
end if
next
End Function