[rt-users] Finding out if a user has been merged

Komarinski, Mark F. mark_komarinski at hms.harvard.edu
Mon Apr 22 14:44:40 EDT 2013

Our Active Directory environment contains a list of email aliases for a user that I can query against, so I'd like to come up with a way of going through that database and merge users in RT to the primary account name.  I've already installed RT-Extension-MergeUsers and can do it by hand, but doing this in an automated fashion would be better given the thousands of users we have and skip over accounts that have already been merged.

Here's the snippet I have and comments I threw in along the way.  My problem appears to be that $merged_users has information about the system user rather than about $account.  What am I missing?

my $UnPrivilegedUsers = RT::Users->new ( $RT::SystemUser );

# We only want to search through unprivileged users.

# Start going through the list of users
while ( my $UnPrivilegedUser = $UnPrivilegedUsers->Next ) {

  # Pull out their e-mail address
  my $email_address = $UnPrivilegedUser->EmailAddress;
  my $name = $UnPrivilegedUser->Name;

  # AD does case-sensitive matching, and they all appear to be lowercase
  my $account = checkLDAP(lc($email_address));
  # Account could be found in AD
  if ( $account ) {
    # Get information about this user
    my $merge_user = RT::User->new ( $RT::SystemUser );
    $merge_user->Load ( $account );
    #  Find out what is merged into this account
    my $merged_users = $merge_user->GetMergedUsers;
    if (grep { $_ == $email_address } @{$merged_users->Content} ) {
      print "Accounts already merged: $email_address in $account\n";

More information about the rt-users mailing list