Today at MIIS newsgroup question was asked how to rename AD account with MIIS. This is pretty simple and if I remember correctly this is even covered by MIIS developer reference but I’ve decided to give it quick thought here.

OK – rename operation: if account name is also CS object’s DN this operation has to be performed within Metaverse extension code. This is because this is only place when You can create \ delete \ rename CS objects. Rename operation in MV extension is pretty simply – You just have to change Your CS object DN attribute. Quick code sample – moving account to some defined destination OU if it is not there already:

ConnectedMA adMA = mventry.ConnectedMAs[“AD MA NAME”];

CSEntry csentry = adMA.Connectors.ByIndex[0];
 

string destinationOU = config.DestinationUsersOU;
string currentOU = csentry.DN.ToString().Substring(csentry.DN.ToString().IndexOf(“OU”),
csentry.DN.ToString().Length -csentry.DN.ToString().IndexOf(“OU”));

if (destinationOU.ToLower() != currentOU.ToLower())
{
    ReferenceValue dn = adMA.CreateDN(string.Format(“CN={0},{1}”,csentry[“cn”].StringValue, destinationOU));
   csentry.DN = dn;
}
 

Quick and dirty, just written for this blog – but I think it shows the idea.  

 
In the case that account name is just one of CS attributes You can just simply flow new attribute value with attribute flow (in most cases this will be advanced flow). This is case if You want to change samAccountName and userPrincipalName for Active Directory accounts. Attribute flows are to simply to write an example for it :).