none
User Status from AdGroup Domain Windows Directory

    Question

  • Hi Team,

    I want to see if a user is active or inactive from the windows directory. Is there any way I could get it from the code.

    Thanks,

    Srikant Mishra

    Tuesday, April 25, 2017 7:39 PM

Answers

  • Hi SrikantMishra,

    I am glad that the reply would be helpful to you.

    Please mark the useful reply as answer. This will make answer searching easier in the forum and be beneficial to community members as well.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 5, 2017 2:56 AM
    Moderator

All replies

  • Hi SrikantMishra,

    Thank you for posting here and sorry for late reply.

    You could use the following code to get all the user in AD group.

     public static void GetAD()
            {
                List<string> userNameList = new List<string>();
                using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
                {
                    using (UserPrincipal user = new UserPrincipal(context))
                    {
                        using (PrincipalSearcher searcher = new PrincipalSearcher(user))
                        {
                            foreach (System.DirectoryServices.AccountManagement.UserPrincipal result in searcher.FindAll())
                            {
                                Console.WriteLine(result.Enabled);
                            }
    
                        }
                    }
                }
            }

    And then use AuthenticablePrincipal.Enabled Property to check the status.

    If the principal has not been persisted in the store, this property returns null. After the principal is persisted, the default enabled setting depends on the store. The AD DS and AD LDS stores disable new principals when they are persisted, whereas SAM enables new principals when they are persisted. The application can only set this property to a value after it has been persisted in the store.

    I hope this would be helpful.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, May 1, 2017 7:34 AM
    Moderator
  • Thanks Wendy,

    That was helpful and solved my purpose.

    Thanks,

    Srikant Mishra

    Thursday, May 4, 2017 3:04 PM
  • Hi SrikantMishra,

    I am glad that the reply would be helpful to you.

    Please mark the useful reply as answer. This will make answer searching easier in the forum and be beneficial to community members as well.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 5, 2017 2:56 AM
    Moderator