Active Directory Account Expiry Date & accountExpires calculation

Last post 07-28-2009 8:58 AM by raghu1. 1 replies.

Sort Posts:

  • Active Directory Account Expiry Date & accountExpires calculation

    07-14-2009, 2:41 PM
    • Member
      point Member
    • sexsee1
    • Member since 07-14-2009, 6:39 PM
    • Posts 1

     

    Hello All,
    I am having a difficult time retrieving the Account Expiry Date for a specified user, I am getting this error when it is pulled:
    System.DirectoryServices.PropertyValueCollection

    The code I have been using to try to pull the accountExpires property is as follows:

    try
    {
    SearchResultCollection searchResultCollection = directorySearch2.FindAll();
    string[] stuff = new string[searchResultCollection[0].GetDirectoryEntry().Properties.PropertyNames.Count];
    object[] stuff2 = new object[stuff.Length];
    searchResultCollection[0].GetDirectoryEntry().Properties.PropertyNames.CopyTo(stuff,0);
    searchResultCollection[0].GetDirectoryEntry().Properties.Values.CopyTo(stuff2,0);
    if (searchResultCollection[0].GetDirectoryEntry().Properties.Contains("accountExpires"))
    {

    accountExpiryDate.Text = activeDirectoryRoot2.Properties["accountExpires"].ToString();

    }
    }
    catch (Exception exception)
    {
    MessageBox.Show(this, "The following error was generated: [" + exception.Message + "}", "Program Exception Occured", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    activeDirectoryRoot2.Close();
    this.Cursor = System.Windows.Forms.Cursors.Default;
  • Re: Active Directory Account Expiry Date & accountExpires calculation

    07-28-2009, 8:58 AM
    • Participant
      1,960 point Participant
    • raghu1
    • Member since 10-28-2005, 11:50 AM
    • Posts 472

    And where is the error. Not sure why you have so many objects. Usually all directory entries have the AccountExpires attribute. A few questions: where is directorySearch2 pointing to ?. The accountExpires is set in AD ticks, you need to convert it to date. There is a simple function for this.

Page 1 of 1 (2 items)