Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy Global groups from one userid to another 1

Status
Not open for further replies.

sneeland

MIS
Jan 27, 2004
49
US
I get requests all the time that say 'setup UserA to be in the same groups as UserB'. Anyone have a simple way to do this copy other than the time-intensive eyeball analysis I have to do???

Thanks!
Steve
 
Don't have access to a server at the moment but I believe you can just right click the "template User" and slect Copy.

I hope you find this post helpful.

Regards,

Mark
 
Yes. all you have to do is a copy. A copy will populate the new user with all the same groups as the template. Except any explicit permissions set on the individual user.

 
I left out one key item. Both Users already exist. Guess that's important....
 
Very important. You will then need to do the following with vbscript.

1. bind to user 1.
2. enumerate all of the groups they area member of into an array.
3. bind to user 2
4. join user to to each group in array.

LMK if you need help with the actual code.

I hope you find this post helpful.

Regards,

Mark
 
I am working with simple exercises right now to self-train myself, so if you do have code for this I would be extremly thankful.

To accomplish this I have had to print a listing of groups User1 belongs to then note the groups that User2 has then...UUGH!

Mark's our hero!

Thanks.
Steve
 
This script is untested but I believe shoudl be good to go. Give it a try and report back your results please.

Code:
'==========================================================================
'
' NAME: <CopyGroupsUserToUser.vbs>
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 2/6/2006
' COPYWRITE (C) 2003, All Rights Reserved
'
'
' COMMENT: <comment>
'
'==========================================================================

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

'Grab the user name
UserString1 = InputBox("Enter Template User Name", "Who should I copy?")
UserString2 = InputBox("Enter Target User Name", "Who should I add groups to?")
'Bind to the user object to get user name and check for group memberships later
Set UserObj1= GetObject("WinNT://" & DomainString & "/" & UserString1)
Set UserObj2= GetObject("WinNT://" & DomainString & "/" & UserString2)

For Each GroupObj In UserObj1.Groups
 BindJoinUser(GroupObj.Name)
Next

Function BindJoinUser(GroupName)
GroupLDAP = SearchDistinguishedName(GroupName)
Set objGroup = GetObject("LDAP://" & GroupLDAP)
objGroup.Add UserObj2
End Function

Public Function SearchDistinguishedName(ByVal vSAN)
    ' Function:     SearchDistinguishedName
    ' Description:  Searches the DistinguishedName for a given SamAccountName
    ' Parameters:   ByVal vSAN - The SamAccountName to search
    ' Returns:      The DistinguishedName Name
    Dim oRootDSE, oConnection, oCommand, oRecordSet

    Set oRootDSE = GetObject("LDAP://rootDSE")
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Open "Provider=ADsDSOObject;"
    Set oCommand = CreateObject("ADODB.Command")
    oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
        ">;(&(objectCategory=Group)(samAccountName=" & vSAN & "));distinguishedName;subtree"
    Set oRecordSet = oCommand.Execute
    On Error Resume Next
    SearchDistinguishedName = oRecordSet.Fields("DistinguishedName")
    On Error GoTo 0
    oConnection.Close
    Set oRecordSet = Nothing
    Set oCommand = Nothing
    Set oConnection = Nothing
    Set oRootDSE = Nothing
End Function

I hope you find this post helpful.

Regards,

Mark
 
Will give this a try this week. I'm in AIX training all week so I'll do my best to get this in. Stay tuned....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top