ML
    • Recent
    • Categories
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Powershell - Count AD users

    IT Discussion
    powershell count ad
    5
    13
    3.1k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • gjacobseG
      gjacobse
      last edited by gjacobse

      I don't do PS,... but I need a script to count the number of AD users,.... I've tried several but they all error - LIKELY since I don't know PS and am not keying the sting values (verb-noun) correctly..

      ObsolesceO 1 Reply Last reply Reply Quote 2
      • scottalanmillerS
        scottalanmiller
        last edited by

        We will need to see the script and the command to know what to fix.

        1 Reply Last reply Reply Quote 0
        • gjacobseG
          gjacobse
          last edited by

          Ah - okay ... found this that works...

          (Get-ADUser -filter *).count
          

          Gives total count of AD accounts - Windows and Users.

          1 Reply Last reply Reply Quote 1
          • gjacobseG
            gjacobse
            last edited by

            Try this one?

            (Get-ADUser -filter * -searchbase "OU=Vancouver, OU=MyCompany, DC=Domain, DC=Local").count
            

            the AD has two OUs, Both OUs are two words with (space).

            dbeatoD 1 Reply Last reply Reply Quote 1
            • gjacobseG
              gjacobse
              last edited by

              Gonna try to edit this and see...

              https://gallery.technet.microsoft.com/scriptcenter/Powershell-script-to-5edcdaea

              1 Reply Last reply Reply Quote 0
              • dbeatoD
                dbeato @gjacobse
                last edited by

                @gjacobse This one works. But you can take a look at this 🙂 From Neally.
                https://community.spiceworks.com/topic/1926864-counting-all-enabled-and-disabled-users-in-ad
                Pretty neat.

                gjacobseG 1 Reply Last reply Reply Quote 0
                • gjacobseG
                  gjacobse @dbeato
                  last edited by

                  @dbeato said in Powershell - Count AD users:

                  @gjacobse This one works. But you can take a look at this 🙂 From Neally.
                  https://community.spiceworks.com/topic/1926864-counting-all-enabled-and-disabled-users-in-ad
                  Pretty neat.

                  Where is my bottle of bleach? SW - Really? jK - thanks will look at that now.

                  1 Reply Last reply Reply Quote 0
                  • dbeatoD
                    dbeato
                    last edited by dbeato

                    Here it is so you don't need to go there 🙂

                    
                    $allDisabldAccounts = (Search-ADAccount -AccountDisabled).count
                    Write-Output "Disabled accounts:`t`t $allDisabldAccounts"
                    $all = (get-aduser -Filter *).count
                    $allactive = $all - $allDisabldAccounts
                    Write-Output "Active Accounts:`t`t $allactive"
                    Write-Output "All Accounts:`t`t`t $all"
                    gjacobseG 1 Reply Last reply Reply Quote 1
                    • gjacobseG
                      gjacobse @dbeato
                      last edited by

                      @dbeato said in Powershell - Count AD users:

                      $allDisabldAccounts = (Search-ADAccount -AccountDisabled).count
                      Write-Output "Disabled accounts:tt $allDisabldAccounts"
                      $all = (get-aduser -Filter *).count
                      $allactive = $all - $allDisabldAccounts
                      Write-Output "Active Accounts:tt $allactive"
                      Write-Output "All Accounts:tt`t $all"

                      Yup,.. nice.
                      Thank you

                      Disabled accounts: 11
                      Active Accounts: 201
                      All Accounts: 212

                      1 Reply Last reply Reply Quote 0
                      • dbeatoD
                        dbeato
                        last edited by

                        Yeah, it works nice, you can use the filter of your OU if you want too.

                        gjacobseG 1 Reply Last reply Reply Quote 0
                        • gjacobseG
                          gjacobse @dbeato
                          last edited by

                          @dbeato said in Powershell - Count AD users:

                          Yeah, it works nice, you can use the filter of your OU if you want too.

                          Thanks - I can already see that I want to do more with it. But I didn't need that level tonight. Maybe next week when I have more time... yea.. like THAT will happen.

                          1 Reply Last reply Reply Quote 1
                          • ObsolesceO
                            Obsolesce @gjacobse
                            last edited by

                            @gjacobse said in Powershell - Count AD users:

                            I don't do PS,... but I need a script to count the number of AD users,.... I've tried several but they all error - LIKELY since I don't know PS and am not keying the sting values (verb-noun) correctly..

                            Or, open up Active Directory Users and Computers, right-click on your domain, click find.

                            In the find window, specify only users to search for, then click the Find button. There will be a count at the bottom.

                            (if there wasn't a specific reason to use PowerShell)

                            1 Reply Last reply Reply Quote 2
                            • J
                              joelbarlow40
                              last edited by joelbarlow40

                              You can try the following command:

                              (get-aduser -filter *).count

                              For only Enabled User Accounts
                              (get-aduser -filter *|where {$_.enabled -eq "True"}).count

                              For only Disabled User Accounts
                              (get-aduser -filter *|where {$_.enabled -ne "False"}).count

                              1 Reply Last reply Reply Quote 0
                              • 1 / 1
                              • First post
                                Last post