O'Reilly logo

Active Directory Cookbook by Robbie Allen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

6.7. Copying a User

Problem

You want to copy an existing user account, which may be serving as a template, in order to create a new account.

Solution

Using a graphical user interface

  1. Open the Active Directory Users and Computers snap-in.

  2. In the left pane, browse to the parent container of the template user object.

  3. In the right pane, right-click on the user and select Copy.

  4. Enter the name information for the new user and click Next.

  5. Enter a password, check any options you want enabled, and click Next.

  6. Click Finish.

Using VBScript

' This code copies the attributes in the Attrs array from an 
' existing object to a new one.
' ------ SCRIPT CONFIGURATION ------
arrAttrs        = Array("department","co","title","l", "c", "st")
strParentDN     = "<ParentContainer>"   ' e.g. cn=Users,dc=rallencorp,dc=com
strTemplateUser = "<TemplateUserName>"  ' e.g. template-user-sales
strNewUser      = "<NewUserName>"       ' e.g. jdoe
strPassword     = "<Password>" ' ------ END CONFIGURATION --------- Const ADS_UF_NORMAL_ACCOUNT = 512 ' from ADS_USER_FLAG_ENUM Set objTemplate = GetObject("LDAP://cn=" & strTemplateUser & _ "," & strParentDN) Set objParent = GetObject("LDAP://" & strParentDN) Set objUser = objParent.Create("user", "cn=" & strNewUser) objUser.Put "sAMAccountName", strNewUser objUser.Put "userAccountControl", ADS_UF_NORMAL_ACCOUNT for each strAttr in arrAttrs objUser.Put strAttr, objTemplate.Get(strAttr) next objUser.SetInfo objUser.SetPassword(strPassword) objUser.AccountDisabled = FALSE objUser.SetInfo WScript.Echo "Successfully ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required