Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

December 22, 2006 12:00 AM

Copy Group Membership from User to User

Windows IT Pro
InstantDoc ID #94471
Rating: (2)
Downloads
94471.zip

In “Copy Group Memberships the Easy Way” (August 2006, InstantDoc ID 50424), I provided a batch-file script—CopyGroup.bat—which copies Active Directory (AD) group memberships from one group to another in Exchange Server 2003 and Exchange 2000 Server. I've written a follow-up script—CopyUsersGroups.bat in Listing 1—that you can use to easily copy group membership from one user to another. (Note that some code in the listing wraps to multiple lines because of space constraints.) This solution will save you a lot of time when you need to give a new user the same group membership as another existing user in the company. You can use CopyUsersGroups.bat to copy an account, including the group memberships when an account is created—a capability that's especially useful when you need to copy the group memberships after the account has been created.

Like CopyGroup.bat, CopyUsersGroups.bat uses the Dsquery, Dsget, and Dsmod utilities to find and copy group memberships. Windows Server 2003 includes these three tools. Alternatively, you can install them from the Windows Server 2003 Administration Tools Pack (adminpak.msi).

In addition to CopyUsersGroups .bat, the solution requires an .ini file— utils.ini in Figure 1—which you need to customize. In utils.ini, substitute the path to your Dsquery, Dsget, and Dsmod utilities for sourcedir and the name of your own domain controller (DC) for DomainControllerName. CopyUsersGroups.bat and utils.ini must be in the same folder (e.g., C:\admin). Modify your PATH variable to include this folder.

To display the command's Help screen, in a command-shell window, enter the script name without any parameters. To run the script, enter the command as follows:

CopyUsersGroups.bat
  FromUser ToUser 

(Be sure to type the actual command on one line.) Replace the FromUser and ToUser parameters with the appropriate AD sAMAccountName attributes, which are displayed when you invoke the script without parameters.

—Frank Houbak Kristiansen

Related Content:

ARTICLE TOOLS

Comments
  • Karen
    3 years ago
    Jan 27, 2009

    The code might not be working for you because the code in Listing 1 was wrapped to multiple lines. Unlike most Windows shell scripting commands, wrapping For commands can cause them to fail, especially when you're using the /F switch to parse a file's contents. I hunted down the original CopyUsersGroups.bat script, in which no lines are wrapped. I placed this script in the 94471.zip file. In addition, I placed the original sample .ini file (utils.ini) that you can adapt and use. You can obtain CopyUsersGroups.bat and utils.ini by clicking the "Download the Code Here" button at the top of the page.

    If you find that the original CopyUsersGroups.bat script doesn't work for you, check to see if your .ini file's path (i.e., the path you set to the cfgfile variable in the script) includes spaces. One limitation of using the For command to parse files is that spaces in a file's path will cause the For command to fail. If your .ini file's path includes spaces, see the article "Two Tricks for Your Scripting Toolbelt" (enter 38418 in the InstantDoc ID box or go to http://windowsitpro.com/article/articleid/38418/38418.html) for information on how to handle those spaces. (The typical technique of enclosing the file path in double quotes doesn't work in this situation.) "Two Tricks for Your Scripting Toolbelt" was originally accessible only to VIP members, but I now opened this article up for public viewing in case you need to read it.

    If you're still having problems with the script after trying the original script and handling any spaces, please let me know.

    Karen Bemowski, senior editor, Windows IT Pro and SQL Server Magazine

  • bbeers
    3 years ago
    Jan 26, 2009

    Has anyone gotten the copyusersgroups.bat to work?

You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.