finding local grp members

Discussion in 'Scripting' started by James, Mar 8, 2005.

  1. James

    James Guest

    i've a AD global grp in the local machine administrators grp.

    is there a script or function to return value that AD global grp exists ?
     
    James, Mar 8, 2005
    #1
    1. Advertisements

  2. Hi

    To test if a domain group exists or not, this should work:

    '--------------------8<----------------------

    sDomainGroup = "some group name here"

    Set oWshNet = CreateObject("WScript.Network")
    sNetBIOSDomain = oWshNet.UserDomain

    On Error Resume Next
    Set oDomainGroup = GetObject("WinNT://" & sNetBIOSDomain & "/" _
    & sDomainGroup & ",group")

    If Err.Number = 0 Then
    WScript.Echo "Domain group found"
    Else
    WScript.Echo "Domain group not found"
    End If
    On Error Goto 0
    '--------------------8<----------------------
     
    Torgeir Bakken \(MVP\), Mar 8, 2005
    #2
    1. Advertisements

  3. James

    James Guest

    i m actually refering to the local machine administrators grp, not the
    network. Otherwise it will always be found.
     
    James, Mar 9, 2005
    #3
  4. Hi

    Here is a script that will check if a domain group exists in
    a local group:

    '--------------------8<----------------------
    Set objWshNet = CreateObject("WScript.Network")

    ' Computer to search in
    strComputer = objWshNet.ComputerName

    ' Group to search in
    strGroup = "Administrators"

    ' Group to search for (include domain name)
    strDomainGroup = objWshNet.UserDomain & "/" & "Domain Admins"

    Set objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")

    bolGroupExists = False ' init value
    For Each objMember in objGroup.Members

    arrADsPath = Split(objMember.ADsPath, "/")

    If Ubound(arrADsPath) = 3 Then
    If LCase(arrADsPath(2) & "/" & arrADsPath(3)) = LCase(strDomainGroup) Then
    bolGroupExists = True
    Exit For
    End If
    End If
    Next

    If bolGroupExists Then
    WScript.Echo "The group " & strDomainGroup _
    & " is found in the group " & strGroup
    Else
    WScript.Echo "The group " & strDomainGroup _
    & " is NOT found in the group " & strGroup

    End If

    '--------------------8<----------------------
     
    Torgeir Bakken \(MVP\), Mar 9, 2005
    #4
    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.