March 15

Create a Solution to Synchronize Account Expiry : Step 5 – Add new run profile

As next 4 run profiles need to be created:

  • Full Import
  • Full Synchronization
  • Delta Import
  • Delta Synchronization

The run profiles need to be created with exactly these run profile names, that the AAD Connect scheduler can pick up these run profiles.

Here are the steps how to create a new run profile:

  1. click on the connectors tab in the synchronization service manager, select our new connector AddRunProfile
  2. click on configure run profile CreateNewProfile
  3. This will open a new window where the list of the run profiles is empty, so click on “New Profile…” to add new run profileAddRunProfileNewProfile
  4. Where you need to add a display name for the new run profile. The name of the run profile should be capitalized and written as aboveAddNewRunProfile_ProfileName
  5. click on next, and select the type Full Import (Stage Only) AddNewRunProfile_ProfileType
  6. click on next, and you do not need to change anything in the following window AddNewRunProfile_ConnectorConfig
  7. click on finish
  8. Repeat this step for other run profiles as well.

 

 

And that’s it. All expired accounts will be disabled as wished. And this process works in delta mode.

Category: AAD Connect, AccountExpires | Comments Off on Create a Solution to Synchronize Account Expiry : Step 5 – Add new run profile
March 11

Create a Solution to Synchronize Account Expiry : Step 4 – Add Synchronization Rule for the new connector

After the new connector is created the next step is to create synchronization rules. Open the AAD Connect Synch Rules Editor and ensure that the inbound flow direction is selected. Click on new to create a new synchronization rule:

Add a name for example: Disabled expired accounts select the name of the created connector at connected system. The object type should be person for connected system object type and for metaverse object type as well. The rule type should be join and I’d suggest a precedence lower than 100. See you here:

 

AADC_CreateNewSynchRule_Description

 

 

The scoping filter can be empty, but we need to set up a join rule. We need here to select sourceAnchor to sourceAnchor. I do not recommend to use anything else.

 

AADC_CreateNewSynchRule_JoinRule

 

 

And now the highlight, the transformation. This should be a constant flow to accountEnabled with the constant value of FALSE.

 

AADC_CreateNewSynchRule_AddTransformation

 

 

Next: https://happyts.tech/create-a-solution-to-synchronize-account-expiry-step-5-add-new-run-profile/

Prev: https://happyts.tech/create-a-solution-to-synchronize-account-expiry-step-3-add-the-new-connector-to-aad-connect/

 

Category: AAD Connect, AccountExpires, ADSync | Comments Off on Create a Solution to Synchronize Account Expiry : Step 4 – Add Synchronization Rule for the new connector
March 7

Create a Solution to Synchronize Account Expiry : Step 3 – Add the new connector to AAD Connect

the next step is really exciting: add our new connector to AAD Connect:

  1. at first you need to copy the complied dll and pdb file in to the folder: C:\Program Files\Microsoft Azure AD Sync\Extensions AADC_AddFilesToExtensionsFolder
  2. As next Open the AAD Connect Synchronization Service Console
  3. Click on Connectors
  4. Click on Create AADC_CreateNewConnector
  5. Select the Connector Type: Extensible Connectivity 2.0 and Enter a Name for the connect e.g. 9th_AADC_CreateNewConnector_Name
  6. Click on Browse and select the Dll,: ExpiredAccountsConnector.dll and click  ok10th_AADC_CreateNewConnector_SelectDll
  7. On the page click on refresh interfaces 11th_AADC_CreateNewConnector_RefreshInterface
  8. Click on Next
  9. The next windows shows the partition, here just click on next, do not need to change anything  13th_AADC_CreateNewConnector_Partition
  10. Select the object:Person    14th_AADC_CreateNewConnector_ObjectType
  11. Select the Attributes (I’d recommend to select them all) 15th_AADC_CreateNewConnector_Attributes
  12. Click Next
  13. On the next page you will see the configuration of the anchor, you do not need to change this 16th_AADC_CreateNewConnector_Anchor
  14. Click Finish

 

Next: https://happyts.tech/create-a-solution-to-synchronize-account-expiry-step-4-add-synchronization-rule-for-the-new-connector/

Category: AAD Connect, AccountExpires, ADSync | Comments Off on Create a Solution to Synchronize Account Expiry : Step 3 – Add the new connector to AAD Connect
February 12

Create a Solution to Synchronize Account Expiry : Step 2 – Build a new connector (aka ManagementAgent)

Here is the source code for the connector, what will import the information about the expiry and looks like this:

 

AADC_SConsole_importedData

 

and here is the code, what you can compile using VisualStudio (community edition should work as well). You need to add the following dll as reference to the project:

C:\Program Files\Microsoft Azure AD Sync\Bin\Assemblies\Microsoft.MetadirectoryServicesEx.dll

you can find further information about the ECMA 2 API here:

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/forefront-2010/hh859557(v=vs.100)?redirectedfrom=MSDN

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.MetadirectoryServices;
using System.Data.SqlClient;
using System.Data;
using System.Diagnostics;
using ConnectionState = System.Data.ConnectionState;


namespace AccountExpiredMA
{

        public class EzmaExtension :
        IMAExtensible2CallImport,      
         IMAExtensible2GetSchema,
         IMAExtensible2GetCapabilities,
         IMAExtensible2GetParameters
        {
            private int m_importDefaultPageSize = 12;
            private int m_importMaxPageSize = 50;

            SqlConnection conn;
            SqlCommand sqlCmd;

            private const string OBJECT_ID = "object_id";
            private const string OBJECT_TYPE = "object_type";
            private const string SOURCE_ANCHOR = "sourceAnchor";
            private const string DISPLAY_NAME = "displayName";
            private const string USER_PRINCIPAL_NAME = "userPrincipalName";
            private const string EXPIRY_ATTRIBUTE_KEY = "Metaverse Attribute for accountExpires";
            private const string DEFAULT_EXPIRY_ATTR = "extensionAttribute10";
            private const string EXPIRY_DATE = "expiryDate";
            private const string CURRENT_DATE = "currentDate";
            private const string EXPIRED = "expired";
            private const string SQL_SERVER_KEY = "SQL server";
            private const string SQL_SERVER_DB_KEY = "SQL Database";
            private string EXPIRY_ATTRIBUTE = DEFAULT_EXPIRY_ATTR;
            private string WATERMARK_ATTRIBUTE = "last_modification_date";
            private Schema currentSchema;
            private const string OBJECT_TYPE_PERSON = "Person";
            private const string TABLE_NAME = "expiredAccounts";


            //
            // Constructor
            //
            public EzmaExtension()
            {
                //
                // TODO: Add constructor logic here
                //
            }

            /// <summary>
            /// Capabilities of the Extensible MA
            /// </summary>
            public MACapabilities Capabilities
            {
                get
                {
                    MACapabilities myCapabilities = new MACapabilities();
                    myCapabilities.ConcurrentOperation = true;
                    myCapabilities.ObjectRename = false;
                    myCapabilities.DeleteAddAsReplace = true;
                    myCapabilities.DeltaImport = true;
                    myCapabilities.DistinguishedNameStyle = MADistinguishedNameStyle.None;
                    myCapabilities.NoReferenceValuesInFirstExport = false;
                    myCapabilities.Normalizations = MANormalizations.None;
                    myCapabilities.ObjectConfirmation = MAObjectConfirmation.Normal;
                    return myCapabilities;
                }
            }

            /// <summary>
            /// Parameter settings / configuration page of the Management Agent
            /// This function will be called for each of the pages
            /// </summary>
            /// <param name="configParameters"></param>
            /// <param name="page"></param>
            /// <returns></returns>
            public IList<ConfigParameterDefinition> GetConfigParameters(KeyedCollection<string, ConfigParameter> configParameters,
                                                                ConfigParameterPage page)
            {
                List<ConfigParameterDefinition> configParametersDefinitions = new List<ConfigParameterDefinition>();

                switch (page)
                {
                    case ConfigParameterPage.Connectivity:
                        configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(SQL_SERVER_KEY, ""));
                        configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(SQL_SERVER_DB_KEY, string.Empty,"ADSync"));
                        configParametersDefinitions.Add(ConfigParameterDefinition.CreateDividerParameter());
                        configParametersDefinitions.Add(ConfigParameterDefinition.CreateLabelParameter("Please enter the name of the metaverse attribute, what contains the expiry date."));
                        configParametersDefinitions.Add(ConfigParameterDefinition.CreateStringParameter(EXPIRY_ATTRIBUTE_KEY, string.Empty,DEFAULT_EXPIRY_ATTR));
                        break;


                    case ConfigParameterPage.Global: 
                        //// not required for our purposes
                        break;


                    case ConfigParameterPage.Partition:
                        //// partitioning is possible only with LDAP style DN
                        break;

                    case ConfigParameterPage.RunStep:
                        //// no additional setting is required here
                        break;
                }

                return configParametersDefinitions;
            }



            /// <summary>
            /// This function will be called if the parameters will be validated
            /// </summary>
            /// <param name="configParameters"></param>
            /// <param name="page"></param>
            /// <returns></returns>
            public ParameterValidationResult ValidateConfigParameters(KeyedCollection<string, ConfigParameter> configParameters,
                                                                       ConfigParameterPage page)
            {
                ParameterValidationResult myResults = new ParameterValidationResult();
                return myResults;
            }


            /// <summary>
            /// This function build the schema of the management agent. we have here a fixed schema.
            /// The objectType contains only person, the anchor attribute is fixed.
            /// But there is an option to select / unselect attributes
            /// </summary>
            /// <param name="configParameters"></param>
            /// <returns></returns>
            public Schema GetSchema(KeyedCollection<string, ConfigParameter> configParameters)
            {
                //// set the name of the Exipry attribute to the attribute, what is added on the config page
                EXPIRY_ATTRIBUTE = configParameters[EXPIRY_ATTRIBUTE_KEY].Value;

                //// create the object type in the schema: Person
                Microsoft.MetadirectoryServices.SchemaType personType = Microsoft.MetadirectoryServices.SchemaType.Create(OBJECT_TYPE_PERSON, true);

                //// create the schema attributes
                SchemaAttribute CS_ATTR_Anchor = SchemaAttribute.CreateAnchorAttribute(OBJECT_ID, AttributeType.String, AttributeOperation.ImportOnly);
                SchemaAttribute CS_ATTR_ObjectType = SchemaAttribute.CreateSingleValuedAttribute(OBJECT_TYPE, AttributeType.String, AttributeOperation.ImportOnly);
                SchemaAttribute CS_ATTR_DisplayName = SchemaAttribute.CreateSingleValuedAttribute(DISPLAY_NAME, AttributeType.String, AttributeOperation.ImportOnly);
                SchemaAttribute CS_ATTR_UserPrincipalName = SchemaAttribute.CreateSingleValuedAttribute(USER_PRINCIPAL_NAME, AttributeType.String, AttributeOperation.ImportOnly);
                SchemaAttribute CS_ATTR_sourceAnchor = SchemaAttribute.CreateSingleValuedAttribute(SOURCE_ANCHOR, AttributeType.String, AttributeOperation.ImportOnly);
                SchemaAttribute CS_ATTR_expired = SchemaAttribute.CreateSingleValuedAttribute(EXPIRED, AttributeType.String, AttributeOperation.ImportOnly);
                SchemaAttribute CS_ATTR_expiryAttribute = SchemaAttribute.CreateSingleValuedAttribute(EXPIRY_ATTRIBUTE, AttributeType.String, AttributeOperation.ImportOnly);
                SchemaAttribute CS_ATTR_ExpiryDate = SchemaAttribute.CreateSingleValuedAttribute(EXPIRY_DATE, AttributeType.String, AttributeOperation.ImportOnly);
                
                //// add the attributes to the object type
                personType.Attributes.Add(CS_ATTR_Anchor);
                personType.Attributes.Add(CS_ATTR_ObjectType);
                personType.Attributes.Add(CS_ATTR_DisplayName);
                personType.Attributes.Add(CS_ATTR_UserPrincipalName);
                personType.Attributes.Add(CS_ATTR_sourceAnchor);
                personType.Attributes.Add(CS_ATTR_expired);
                personType.Attributes.Add(CS_ATTR_expiryAttribute);
                personType.Attributes.Add(CS_ATTR_ExpiryDate);
                
                //// create the schema object
                Schema schema = Schema.Create();
                
                //// add the object type to the schema
                schema.Types.Add(personType);
                return schema;
            }



         /// <summary>
         ///  This is the first function what will be called during the import run-profile.
         ///  This function takes care about the connection to data source in our case to the sql database.
         /// </summary>
         /// <param name="configParameters">This collection contains the configured configuration data.</param>
         /// <param name="types">
         ///        This parameter contains the configured schema: selected object type - in our case person and the
         ///        selected attributes.
         /// </param>
         /// <param name="importRunStep">
         ///        This contains the run step, what contains also the information, 
         ///        if the running run profile delta import or full import.</param>
         /// <returns></returns>
            public OpenImportConnectionResults OpenImportConnection(
                                           KeyedCollection<string, ConfigParameter> configParameters,
                                           Schema types,
                                           OpenImportConnectionRunStep importRunStep)
            {
                WriteLog("Open Connection");

                ////    reading the data from the config parameter
                string myServer = configParameters[SQL_SERVER_KEY].Value;
                string myDB = configParameters[SQL_SERVER_DB_KEY].Value;

                ////    set the selected attribute for the expiry attribute
                string expiryMVAttr = configParameters[EXPIRY_ATTRIBUTE_KEY].Value;
                
                ////    set the global schema variable 
                currentSchema = types;

                ////    set up the SQL connection string
                string myConnection = $"Server = '{myServer}';Initial Catalog='{myDB}';Integrated Security=True";
                WriteLog($"connection string:{myConnection}");
                
                ////    set up the SQL connection
                conn = new SqlConnection(myConnection);
                sqlCmd = new SqlCommand();
                sqlCmd.CommandType = CommandType.Text;

                /// set up the SQL command, that is used to retrieve the data from the SQL table
                string cmdText = $@"
                Use ADsync;
                SELECT
                     [object_id]
                    ,[object_type]
                    ,[sourceAnchor]
                    ,[displayName]
	                ,[userPrincipalName]
	                ,[extensionAttribute10]
                    ,CAST( [{expiryMVAttr}] as date) as expiryDate
                    ,CAST(GETDATE() AS DATE) as currentDate
	                ,'TRUE' As expired
                    ,[last_modification_date]

                FROM[ADSync].[dbo].[mms_metaverse]

                WHERE
                    object_type = 'person'
                    AND {expiryMVAttr} is not null
                    AND(CAST( [{expiryMVAttr}] as date) < CAST(GETDATE() AS DATE) )
                    ";

                 ////   check if the select run profile is delta import and if there is a watermark (CustomData)
                  if (importRunStep.ImportType == OperationType.Delta && importRunStep.CustomData.Length > 0)
                  {
                    ////    retrieve the watermark and append to the SQL query  
                    string waterMark = Convert.ToString(importRunStep.CustomData);
                    if (!string.IsNullOrWhiteSpace(waterMark))
                    {
                        string deltaSuffix = $" AND (CAST( [{expiryMVAttr}] as date) >= '{waterMark}'";
                        cmdText += deltaSuffix;
                    }
                  }                  


                WriteLog($"Command text: {cmdText}");
                ////    set up the SQL command
                sqlCmd.CommandText = cmdText;
                sqlCmd.Connection = conn;

                ///     try to open the SQL connection
                try
                {
                    conn.Open();
                }
                catch (InvalidOperationException iopEx)
                {
                    throw new FailedConnectionException("Can't open connection to SQL Server!", iopEx);
                }
                catch (SqlException sqlEx)
                {
                    throw new FailedConnectionException("Can't open connection to SQL Server!", sqlEx);
                }
                catch (System.Configuration.ConfigurationException scceEx)
                {
                    throw new FailedConnectionException("Can't open connection to SQL Server!", scceEx);
                }            

                return new OpenImportConnectionResults();
            }


            /// <summary>
            /// this function is called after the connection is opened to retrieve the data
            /// </summary>
            /// <param name="importRunStep"></param>
            /// <returns></returns>
            public GetImportEntriesResults GetImportEntries(GetImportEntriesRunStep importRunStep)
            {
                GetImportEntriesResults importReturnInfo = new GetImportEntriesResults();
                List<CSEntryChange> csentries = new List<CSEntryChange>();
                
                ////    set up the SQL Data Adapter and fill the data set
                SqlDataAdapter adapter = new SqlDataAdapter(sqlCmd);
                DataSet da = new DataSet();
                adapter.Fill(da, TABLE_NAME);

                //// create a mapping table between column name and column id
                Dictionary<string, int> columnMapping = new Dictionary<string, int>();
                foreach (DataColumn column in da.Tables[TABLE_NAME].Columns)
                {
                    columnMapping.Add(column.ColumnName, column.Ordinal);
                }

                string currentWaterMark = string.Empty;

                ////    retrieve the configured schema for the object type person
                KeyedCollection<string, SchemaAttribute> selectedAttributes = currentSchema.Types[OBJECT_TYPE_PERSON].Attributes;


                ////    check if there are any results
                if (null != da.Tables && 0 < da.Tables.Count)
                {
                    WriteLog($"Nr of result: {da.Tables.Count} has been retrieved.");

                    ////    iterate through the result set
                    for (int indexOfResult = 0; indexOfResult <= da.Tables[TABLE_NAME].Rows.Count - 1; indexOfResult++)
                    {
                        //WriteLog($"Current: {indexOfResult} of result: {da.Tables.Count}");
                        ////    create the connector space object, that will be passed as return value to the sync engine
                        CSEntryChange cse = CSEntryChange.Create();
                        cse.ObjectModificationType = ObjectModificationType.Add;
                        cse.ObjectType = OBJECT_TYPE_PERSON;

                        ////    iterate through the columns
                        foreach (string columnName in columnMapping.Keys)
                        {
                            //WriteLog($"Current column: {columnName} ");
                            
                            ////    check if the current attribute is selected
                            if (selectedAttributes.Contains(columnName))
                            {
                                //WriteLog($"Current column is selected: {columnName} ");
                                ////    retrieve the value of the current and selected attribute
                                string attributeValue = RetrieveStringValueFromTable(ref da, ref indexOfResult, ref columnMapping, columnName);
                                if (!string.IsNullOrWhiteSpace(attributeValue))
                                {
                                    //WriteLog($"Current value is: {attributeValue} ");
                                    ////    the attribute value is not empty => add to the object
                                    cse.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(columnName, attributeValue));
                                }
                            }                           
                        }

                        ///     add the connector space object to the result list
                        csentries.Add(cse);                        
                    }
                }
                else
                {
                    ////    the result list is empty
                    WriteLog($"No result has been retrieved.");
                }
                

                ////    set up the return info object the pass as return object
                importReturnInfo.CustomData = currentWaterMark;                
                importReturnInfo = new GetImportEntriesResults();
                importReturnInfo.MoreToImport = false;
                importReturnInfo.CSEntries = csentries;
                return importReturnInfo;
            }


            /// <summary>
            /// auxiliary function to read the object value from the given table
            /// </summary>
            /// <param name="da">DataSet that contains the retrieved data from SQL database</param>
            /// <param name="rowIndex">index of the current row in the data table</param>
            /// <param name="columnMapping">Dictionary that contains the mapping between column name and column index</param>
            /// <param name="attribute">contains the name of the current attribute</param>
            /// <returns></returns>
            private string RetrieveStringValueFromTable(ref DataSet da, ref int rowIndex, ref Dictionary<string, int> columnMapping, string attribute)
            {
               return Convert.ToString(da.Tables[TABLE_NAME].Rows[rowIndex].ItemArray.GetValue(columnMapping[attribute])).Trim();
            }

            
            /// <summary>
            /// after all data are retrieved, the connection needs to be closed
            /// </summary>
            /// <param name="importRunStepInfo"></param>
            /// <returns></returns>
            public CloseImportConnectionResults CloseImportConnection(CloseImportConnectionRunStep importRunStepInfo)
            {
                if (conn.State == ConnectionState.Open)
                {
                    try
                    {
                        conn.Close();
                    }
                    catch (SqlException sqlEx )
                    {
                        WriteLog($"Error while closing the SQL Connection. \n {sqlEx.Message}");
                    }
                }
                return new CloseImportConnectionResults();
            }


            /// <summary>
            /// This function returns the max possible import page size
            /// </summary>
            public int ImportMaxPageSize
            {
                get
                {
                    return m_importMaxPageSize;
                }
            }


            /// <summary>
            /// This function returns the default import page size
            /// </summary>
            public int ImportDefaultPageSize
            {
                get
                {
                    return m_importDefaultPageSize;
                }
            }

                
            /// <summary>
            /// This function writes message to the Windows Application Event log
            /// </summary>
            /// <param name="message">This is the message string, what will be written into the Application Event Log</param>
            internal void WriteLog(string message)
            {
                //EventLog.CreateEventSource("ADSync", "Application");
                EventLog objEvent = new EventLog();
                objEvent.Source = "ADSync";
                StringBuilder eventText = new StringBuilder();
                eventText.Append($"ExpireAccountsConnector: {message}");
                objEvent.WriteEntry(eventText.ToString(), EventLogEntryType.Information);
            }


        }
    
}

And if you wish to download the precompiled connector you can do this here:

ExpiredAccountsConnector

 

the next step is to create a connector: https://happyts.tech/create-a-solution-to-synchronize-account-expiry-step-3-add-the-new-connector-to-aad-connect/

Category: AAD Connect, AccountExpires, ADSync | Comments Off on Create a Solution to Synchronize Account Expiry : Step 2 – Build a new connector (aka ManagementAgent)
February 12

Create a Solution to Synchronize Account Expiry : Step 1 – Add a new custom synchronization rule

The very fist thing what you need to plan and decide what is the metaverse attribute, what will contains the date time value for accountExpires. The accountExpires attribute contains ticks, what needs to be converted to date time. For this, we can use the following expression:

IF(IsNull([accountExpires]),NULL,IIF([accountExpires]<9223372036854775807,CStr(DateFromNum([accountExpires])),NULL))

 

You can configure this using the AAD Connect Synchronization Rules editor. Launch this, and click on new:

 

1st_AADC_SREditor_AddNewRule

 

As next a new window appears and you need to select the on-premises Active Directory Connector (account forest) as connected system, select the object type user in the source system and person as metaverse object type. I’d suggest a name as Convert AccountExpires to Date or: In from AD – User AccountExpires conversion. I’d suggest here a low precedence.

 

2nd_AADC_SREditor_Description

 

Click on next to see the scoping filter, what you can either leave empty or you can scope of the users you whish to handle:

3rd_AADC_SREditor_Scoping

 

after clicking on next, you can configure the join rules, but I’d suggest to keep this empty:

 

4th_AADC_SREditor_Join

 

and the last most important part is the conversion it self. You need to select Expression as FlowType and the attribute what you identified to keep the converted value. I’d recommend here a single valued string attribute, e.g. extensionAttribute10

 

5th_AADC_SREditor_Transformation

 

 

After clicking on next a full synchronization on this connector is required to get this attribute filled.

 

An alternative method is to use PowerShell to create this synchronization rule. Here is the rule itself, but you need to replace the id of the connector:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
New-ADSyncRule  `
-Name 'Convert AccountExpires to Date' `
-Identifier 'b6da9d89-b9bc-451c-9b6a-f46256620f50' `
-Description '' `
-Direction 'Inbound' `
-Precedence 90 `
-PrecedenceAfter '00000000-0000-0000-0000-000000000000' `
-PrecedenceBefore '00000000-0000-0000-0000-000000000000' `
-SourceObjectType 'user' `
-TargetObjectType 'person' `
-Connector '<replace with connector guid>'`
-LinkType 'Join' `
-SoftDeleteExpiryInterval 0 `
-ImmutableTag '' `
-OutVariable syncRule


Add-ADSyncAttributeFlowMapping  `
-SynchronizationRule $syncRule[0] `
-Destination 'extensionAttribute10' `
-FlowType 'Expression' `
-ValueMergeType 'Update' `
-Expression 'IIF(IsNull([accountExpires]),NULL,IIF([accountExpires]<9223372036854775807,CStr(DateFromNum([accountExpires])),NULL))' `
-OutVariable syncRule


Add-ADSyncRule  `
-SynchronizationRule $syncRule[0]


Get-ADSyncRule  `
-Identifier 'b6da9d89-b9bc-451c-9b6a-f46256620f50'

 

next step: https://happyts.tech/create-a-solution-to-synchronize-account-expiry-step-2-create-a-new-connector-aka-managementagent/

Category: AAD Connect, AccountExpires | Comments Off on Create a Solution to Synchronize Account Expiry : Step 1 – Add a new custom synchronization rule
January 28

AccountExpire is not synchronized by AAD Connect

I see, that a lot of people has some pain to synchronized the Account Expiry from on-premises Active Directory to Azure AD using AAD Connect.

There are two or more requests on this topic:

https://feedback.azure.com/forums/169401-azure-active-directory/suggestions/31459621-sync-account-expired-useraccountcontrol-to-azure

and

https://office365.uservoice.com/forums/289138-office-365-security-compliance/suggestions/17643847-active-directory-accountexpires-attribute-does-not

 

The reason for this is, that AAD Connect picks up changes from the on-prem AD and the AccountExpires attribute is a static attribute, where you can configure a dateTime (as ticks), when the account should expire. If this date is reached then the account is expired, but there is no change on the object itself. As we know, AAD Connect works state based, this means, AAD Connect picks up changes using the DirSyncControl. Since there is no change on the object, because the configured date on the object itself is static date and this date is reached, there is no change to pick up by AAD Connect. This is the reason, why AAD Connect can’t sync this change.

 

There are some documented workarounds, but these either requires a script that runs regularly (at least once a day) as mentioned here:

https://docs.microsoft.com/en-us/archive/blogs/undocumentedfeatures/use-aad-connect-to-disable-accounts-with-expired-on-premises-passwords

 

or the other solution, what required to run the full sync run profile on the on-prem AD Connector at least once a day:

https://myserverissick.com/2019/01/how-to-make-azure-ad-connect-disable-expired-accounts/

 

I think, that the best solution for this issue is to add a new connector (management agent), where this agent can calculate and populate this value. I’ll evaluate this option and will publish here soon……

 

Happy Troubleshooting!

Category: AAD Connect, AccountExpires | Comments Off on AccountExpire is not synchronized by AAD Connect