none
Active Directory whenCreated attribute RRS feed

  • Question

  • Hi,

    I'm trying to convert the Active Directory "whenCreated" attribute (time in this format: 20120203055042.0Z) extracted from AD into normal DateTime format ('cause I have to do some checks on the date).

    Could you give me some tips on how can I do this with a C# rule extension?

    I triyed with the following but it doesn't work..

    Any help you can give me is appreciated.

    Thanks in advance.

    Francesca

    Thursday, September 13, 2012 8:41 PM

Answers

  • Francesca-

    I don't think you want to use this attribute - it is not replicated so it will vary depending on which domain controller you talk to.

    In any case, what you want is DateTime.FromFileTime(csentry["whenCreated"].IntegerValue).


    My Book - Active Directory, 4th Edition
    My Blog - www.briandesmond.com

    Thursday, September 13, 2012 11:28 PM
    Moderator
  • Hi Francesca,

    I haven't done this in a flow rule but I have done it in stand alone projects.  You have to modify the code slightly and you will have to add a string to define the format.  Try this:

    string format = "yyyyMMddHHmmss.0Z";
    DateTime whenCreated = DateTime.ParseExact(csentry["whenCreated"].StringValue, format, System.Globalization.CultureInfo.InvariantCulture);

    This should allow you to get the generalized string from AD into the DateTime format.

    Bryan

    Tuesday, September 25, 2012 2:40 PM
  • Brian, whenCreated is replicated (as opposed to whenChanged, which is not replicated / FIM will not even expose in the AD attribute list).  Unlike accountExpires and pwdLastSet, which are of "interval" syntax, whenCreated is a "generalized time."

    Exporting to AD generalized times from FIM is a bit tricky: What I found to work was to treat it as a binary value, containing the UTF8 bytes of the DateTime formatted with "yyMMddHHmmssZ".

    Finally, the best way to use DateTime.ParseExact is with the System.Globalization.DateTimeStyles.AssumeUniversal argument, as DateTime parsing has little to no built-in understanding of timezones.

    --Steve

    Tuesday, September 25, 2012 3:45 PM

All replies

  • Francesca-

    I don't think you want to use this attribute - it is not replicated so it will vary depending on which domain controller you talk to.

    In any case, what you want is DateTime.FromFileTime(csentry["whenCreated"].IntegerValue).


    My Book - Active Directory, 4th Edition
    My Blog - www.briandesmond.com

    Thursday, September 13, 2012 11:28 PM
    Moderator
  • Hi Brian, thanks for your reply and suggestion. 

    A clarification.. if I have only one primary domain controller (and others as secondary) ..does the problem exist? Sorry but I'm new with these issues.

    However my check is temporary and I'll remove it when the solution works.. Using your code I get the following error

    System.InvalidOperationException: IntegerValue property can only be used on a integer attribute
       at Microsoft.MetadirectoryServices.Impl.AttributeImpl.get_IntegerValue()
       at Mms_ManagementAgent_AD_MAExtension.MAExtensionObject.Microsoft.MetadirectoryServices.IMASynchronization.MapAttributesForImport(String FlowRuleName, CSEntry csentry, MVEntry mventry) in C:\Users\fim.admin\Documents\AD MAExtension\AD MAExtension.cs:line 257

    Can you tell me why it doesn't work ?

    Thank u very much.

    • Proposed as answer by M.Irfan Friday, September 14, 2012 7:29 AM
    • Unproposed as answer by M.Irfan Friday, September 14, 2012 7:29 AM
    Friday, September 14, 2012 7:06 AM
  • Hi,

    Date and time is in this format. yyyy-MM-ddTHH:mm:ss.000

    When you import attribute converti in this format.

    more over you can read the artical for better understanding.

    http://blog.goverco.com/2010/03/exporting-employeestartdate-to-fim-2010.html

    Regard plz if find useful


    Muhammad Irfan

    • Proposed as answer by M.Irfan Friday, September 14, 2012 7:30 AM
    Friday, September 14, 2012 7:30 AM
  • Hi Francesca,

    I haven't done this in a flow rule but I have done it in stand alone projects.  You have to modify the code slightly and you will have to add a string to define the format.  Try this:

    string format = "yyyyMMddHHmmss.0Z";
    DateTime whenCreated = DateTime.ParseExact(csentry["whenCreated"].StringValue, format, System.Globalization.CultureInfo.InvariantCulture);

    This should allow you to get the generalized string from AD into the DateTime format.

    Bryan

    Tuesday, September 25, 2012 2:40 PM
  • Brian, whenCreated is replicated (as opposed to whenChanged, which is not replicated / FIM will not even expose in the AD attribute list).  Unlike accountExpires and pwdLastSet, which are of "interval" syntax, whenCreated is a "generalized time."

    Exporting to AD generalized times from FIM is a bit tricky: What I found to work was to treat it as a binary value, containing the UTF8 bytes of the DateTime formatted with "yyMMddHHmmssZ".

    Finally, the best way to use DateTime.ParseExact is with the System.Globalization.DateTimeStyles.AssumeUniversal argument, as DateTime parsing has little to no built-in understanding of timezones.

    --Steve

    Tuesday, September 25, 2012 3:45 PM
  • Hi 

    this is me irfan can you plz delete/remove the Ad &DNS and install your program again

                      thnks

    Thursday, May 2, 2013 5:22 PM
  • Hello,

    I have this line:

    Get-AdUser -Filter * -property WhenCreated, lastLogon | sort WhenCreated | ft Name,WhenCreated,lastLogon -Autosize

    I have tried this:

    Get-AdUser -Filter * -property DateTime.FromFileTime(csentry["whenCreated"]).IntegerValue, lastLogon | sort WhenCreated | ft Name,WhenCreated,lastLogon -Autosize

    So the "WhenCreated" attribute shows in a more human friendly way, but it does not work.

    I really don't know where to place the function, whether in the "property" switch o in the Format-Table . It does not work in either of those.

    I have just tried this:

    Get-AdUser -Filter * -property WhenCreated, lastLogon | sort WhenCreated | ft Name,DateTime.ParseExact(csentry["whenCreated"].StringValue,format,System.Globalization.CultureInfo.InvariantCulture) , lastLogon -AutoSize

    But there is an error message as well.

    Thanks in advance.


    Luis Olías.


    • Edited by Luis O.J Thursday, August 8, 2019 7:15 AM
    Thursday, August 8, 2019 7:05 AM