PowerShell Script - Count OUs within a specific domain

Does anyone have a PowerShell Script that can list a count of all objects within the per-OU in a specific domain?
LVL 1
amazon4lifeAsked:
Who is Participating?
 
it_saigeConnect With a Mentor DeveloperCommented:
You mean something like this?
Import-Module ActiveDirectory
Get-ADOrganizationalUnit -Filter * -Properties * | Select-Object @{l="Organizational Unit";e={$_.Name}},@{l="Object Count";e={(Get-AdObject -Filter * -SearchBase $_.DistinguishedName).count}}

Open in new window

Example output -Capture.JPG-saige-
1
 
sAMAccountNameSr. Systems EngineerCommented:
How about this for starters:

Set-Location AD:
(Get-ChildItem "OU=Users,OU=Accounts,DC=domain,DC=com" | select).Count

Open in new window


Just change the DN as needed...  Are you looking for something more flexible?
0
 
Dustin SaundersDirector of OperationsCommented:
Absolutely, but can you be a bit more specific about what you need?  Do you need to count all the containers in a specific OU?  All the users& groups in a specific OU?  Any recursive objects (users, groups, contacts, shared folders)?  etc etc
0
 
Senior IT System EngineerIT ProfessionalCommented:
That is wonderful Richard :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.