public static void FixDistinguishedName(ADObject adObject, string tenantDistinguishedName, Guid tenantGuid, Guid objectGuid, ADObjectId relativeConfigDN = null) { if (adObject == null || string.IsNullOrEmpty(tenantDistinguishedName)) { return; } if (tenantGuid == Guid.Empty || objectGuid == Guid.Empty) { throw new InvalidOperationException(string.Format("Unable to fix distinguished name for ADObject = {0}, TenantGuid = {1}, ObjectGuid = {2}, objectName = {3}.", new object[] { adObject.GetType().Name, tenantGuid, objectGuid, adObject.Name })); } string unescapedCommonName = string.IsNullOrEmpty(adObject.Name) ? objectGuid.ToString() : adObject.Name; ADObjectId adobjectId = new ADObjectId(tenantDistinguishedName, tenantGuid); ADObjectId adobjectId2 = new ADObjectId(adobjectId.GetChildId("Configuration").DistinguishedName, tenantGuid); if (relativeConfigDN != null) { adobjectId2 = new ADObjectId(adobjectId2.GetDescendantId(relativeConfigDN).DistinguishedName, tenantGuid); } ADObjectId id = new ADObjectId(adobjectId2.GetChildId(unescapedCommonName).DistinguishedName, objectGuid); ADObjectId adobjectId3 = (ADObjectId)adObject[ADObjectSchema.ConfigurationUnit]; if (adobjectId3 != null && adobjectId3.Name != null && string.Equals(adobjectId3.Name, adobjectId2.Name, StringComparison.InvariantCultureIgnoreCase)) { return; } adObject[ADObjectSchema.OrganizationalUnitRoot] = adobjectId; adObject[ADObjectSchema.ConfigurationUnit] = adobjectId2; adObject.SetId(id); FfoDirectorySession.FixLegacyExchangeDN(adObject, tenantGuid); FfoDirectorySession.FixDistinguishedNameForADObjectIDs(adObject, tenantDistinguishedName); }