Login script that checks if computer is in Server or Domain Controller group

Discussion in 'Scripting' started by Tim Kelley, Aug 17, 2007.

  1. Tim Kelley

    Tim Kelley Guest

    Is there a way to check if a computer is in the Servers or Domain
    Controllers group when someone logs on to the machine?

    Tim Kelley, Aug 17, 2007
    1. Advertisements

  2. It's easy to check computer group membership, but "Domain Controllers" is an
    OU. There is no group or OU for Servers, unless you created these groups.

    In case you did create groups for this, and assuming all clients are Windows
    2000 or above, the following should work:
    Option Explicit
    Dim objSysInfo, strComputerName, objComputer

    ' Retrieve local computer Distinguished Name.
    Set objSysInfo = CreateObject("ADSystemInfo")
    strComputerDN = objSysInfo.ComputerDN

    ' Bind to computer object.
    Set objComputer = GetObject("LDAP://" & strComputerDN)

    ' Bind to the group to check for membership.
    Set objGroup = GetObject("LDAP://cn=Domain

    ' Check group membership.
    If (objGroup.IsMember(objComputer.AdsPath) = True) Then
    ' Computer object is a member of the group.
    End If
    To check if the computer is in the "ou=Domain Controllers" organizational
    unit, you either must parse the Distinguished Name of the computer object,
    or use the Parent method of the computer object to retrieve the DN of the
    parent container/OU. For example:
    ' Bind to parent container/OU object using Parent method of computer object.
    Set objParent = GetObject(objComputer.Parent)
    ' Retrieve DN of parent.
    strParentDN = objParent.distinguishedName
    ' Check if this is the Domain Controllers OU.
    If (strParentDN = "ou=Domain Controllers,dc=MyDomain,dc=com") Then
    ' Computer is in ou=Domain Controllers.
    End If
    A method to tell if a computer is a server (including a DC) is to check the
    Operating System description. For example:
    If (InStr(UCase(objComputer.OperatingSystem), "SERVER") > 0) Then
    ' Computer has a server operating system.
    End If

    I hope this helps.
    Richard Mueller [MVP], Aug 17, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.