How To Use ADSI to Determine Server Roles (250324)



The information in this article applies to:

  • Microsoft Active Directory Service Interfaces 2.5

This article was previously published under Q250324

SUMMARY

This article demonstrates how to use Active Directory Services Interfaces (ADSI) to determine the role of a computer in a Microsoft Windows domain.

MORE INFORMATION

The following code uses the WinNT provider to loop through all computers in the specified domain. It checks the user flags to determine the role of each computer (either a primary domain controller [PDC]/backup domain controller [BDC], or a member server/workstation on the domain).
Dim oDom
Dim oComputer
Dim oUser
Dim lngFlags
Dim strDomain

strDomain = "<Enter correct domain name here>"

Set oDom = GetObject("WinNT://" & strDomain & ",domain")

oDom.Filter = Array("Computer")
For Each oComputer in oDom
	Set oUser = GetObject("WinNT://" & strDomain & "/" & oComputer.Name & "$,user")
	lngFlags = oUser.Get("UserFlags") And 8192
	If lngFlags = 8192 then
		MsgBox oComputer.Name & " is either a PDC or BDC."
	Else
		MsgBox oComputer.Name & " is either a Member server or Workstation."
	end if
Next

Set oUser = Nothing
Set oComputer = Nothing
Set oDom = Nothing
				

Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kbDSWManage2003Swept kbhowto kbMsg KB250324