Re: Use the "Managed By" field in AD to set as local Admin
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 13 May 2009 10:30:47 -0500
"ErikW" <ErikW@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:5B1EEE64-02BF-4ABE-B709-2B72D0058831@xxxxxxxxxxxxxxxx
Thank you. I'm not that into scripting these things but I will take a look
and see what I can do. I think the way must be in the logon script. "If a
script using ADO to handle this for all computers in bulk interests you,
reply for more" This is very interesting.
Erik
A program as I described earlier is below. I added error trapping in case a
computer is not available (and the script cannot bind to the local
Administrators group) so the program echos a message to the command line
console. The program should be run at a command prompt using cscript. Since
the program does nothing if the user is already a member of the local
Administrators group, you can run it repeatedly until there is no message
about unavailable computers. Of course whomever runs the script needs
sufficient privileges to add members to the group. By default, the group
"Domain Admins" should be a member of the local Administrators group on
every computer joined to the domain. Any member of "Domain Admins" has
permissions. I would expect most users would not have permissions, so a
logon script would fail. If normal users had permission to manage the local
Administrators group in a logon script, there would be no need for the
script.
=========
' VBScript program to make sure the user referred to by the
' managedBy attribute of every computer in the domain is a
' member of the local Administrators group.
Option Explicit
Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
Dim objRootDSE, strDNSDomain, strQuery, adoRecordset
Dim strComputerDN, strComputer, strManagerDN
Dim objAdmGroup, objManager
' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
' Filter on all computer objects with managedBy assigned.
strFilter = "(&(objectCategory=computer)(managedBy=*))"
' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName,sAMAccountName,managedBy"
' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
' Run the query.
Set adoRecordset = adoCommand.Execute
' Enumerate the resulting recordset.
Do Until adoRecordset.EOF
' Retrieve values
strComputerDN = adoRecordset.Fields("distinguishedName").Value
strComputer = adoRecordset.Fields("sAMAccountName").Value
strManagerDN = adoRecordset.Fields("managedBy").value
' Remove trialing "$" character to get NetBIOS name
strComputer = Left(strComputer, Len(strComputer) - 1)
' Bind to user object referred to by managedBy.
Set objManager = GetObject("LDAP://" & strManagerDN)
' Bind to local Administrators group on computer.
' Trap the error if the computer is not available.
On Error Resume Next
Set objAdmGroup = GetObject("WinNT://" & strComputer _
& "/Administrators,group")
If (Err.Number = 0) Then
On Error GoTo 0
' Make sure user is a member of this group.
If (objAdmGroup.IsMember(objManager.AdsPath) = False) Then
objAdmGroup.Add(objManager.AdsPath)
End If
Else
On Error GoTo 0
Wscript.Echo "Unable to bind to Administrators group on " _
& strComputer
End If
' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop
' Clean up.
adoRecordset.Close
adoConnection.Close
--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--
.
- Follow-Ups:
- References:
- Use the "Managed By" field in AD to set as local Admin
- From: ErikW
- Re: Use the "Managed By" field in AD to set as local Admin
- From: Richard Mueller [MVP]
- Re: Use the "Managed By" field in AD to set as local Admin
- From: ErikW
- Use the "Managed By" field in AD to set as local Admin
- Prev by Date: pasword policy
- Next by Date: Re: client = local admin
- Previous by thread: Re: Use the "Managed By" field in AD to set as local Admin
- Next by thread: Re: Use the "Managed By" field in AD to set as local Admin
- Index(es):
Relevant Pages
|