• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

List AD User Accounts Excluding Service Accounts

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    List AD User Accounts Excluding Service Accounts

    I need to get a list of user accounts from Active Directory using C#. This should exclude "Service Accounts". I note from Windows2008R2 + there are now "Managed Service Accounts" which are quasi user accounts masquerading as machines which means they are service level accounts that can be managed at a domain level. Got it? Well I don't want them either. Just flesh and blood users.

    So here's me code

    Code:
    using (DirectorySearcher ds = new DirectorySearcher(_directoryEntry, "(&(objectClass=user)(objectCategory=person))"))
                {
    
                    try
                    {
                        ds.PageSize = 1000;
    
                        /*core data*/
                        ds.PropertiesToLoad.Add("sAMAccountName");
                        ds.PropertiesToLoad.Add("mail");
                        ds.PropertiesToLoad.Add("objectSid");
                        ds.PropertiesToLoad.Add("servicePrincipalName");
    I thought I'd cracked it when I found a property called servicePrincipalName - described in the MSDN as

    Service principal names are associated with the security principal (user or groups) in whose security context the service executes. SPNs are used to support mutual authentication between a client application and a service
    Except that this multivalue propery is emtpy for IUSR and IWAM accounts etc.

    Any takers?

    I will take a powershell example.

    TIA

    Humbly

    The slightly less awesome

    Suity
    Knock first as I might be balancing my chakras.

    #2
    Do you have a project code I can book my time to please.
    'CUK forum personality of 2011 - Winner - Yes really!!!!

    Comment


      #3
      Originally posted by northernladuk View Post
      Do you have a project code I can book my time to please.
      Yes, it's.

      YACCOTBAC

      HTH
      Knock first as I might be balancing my chakras.

      Comment


        #4
        Originally posted by northernladuk View Post
        Do you have a project code I can book my time to please.
        Surely its can you send me your purchase order, I can start work once its received...
        merely at clientco for the entertainment

        Comment


          #5


          Quite.

          I did this

          Code:
          (&(objectClass=user)(objectCategory=person)(mail=*))
          in my LDAP filter.

          Since service accounts shouldn't have email addresses I'm hoping I can enforce this as a rule.

          Flame away.
          Knock first as I might be balancing my chakras.

          Comment


            #6
            Originally posted by suityou01 View Post


            Quite.

            I did this

            Code:
            (&(objectClass=user)(objectCategory=person)(mail=*))
            in my LDAP filter.

            Since service accounts shouldn't have email addresses I'm hoping I can enforce this as a rule.

            Flame away.
            You are making the assumption a user has an email address. That is a brave decision....
            merely at clientco for the entertainment

            Comment


              #7
              Originally posted by eek View Post
              You are making the assumption a user has an email address. That is a brave decision....
              You are not providing an alternative. That's an easy thing to do when criticising.
              Knock first as I might be balancing my chakras.

              Comment


                #8
                Originally posted by suityou01 View Post
                You are not providing an alternative. That's an easy thing to do when criticising.
                I'm still waiting for the purchase order. I will however happily highlight problems within your current approach to emphasis why you need me....
                merely at clientco for the entertainment

                Comment


                  #9
                  Originally posted by suityou01 View Post
                  You are not providing an alternative. That's an easy thing to do when criticising.
                  What about services which send email?

                  Why not use multiple tests on say address, phone number etc.
                  While you're waiting, read the free novel we sent you. It's a Spanish story about a guy named 'Manual.'

                  Comment


                    #10
                    dir \Users\*

                    Comment

                    Working...
                    X