Solved

PowerShell Script - Count OUs within a specific domain

Posted on 2016-10-19
4
54 Views
Last Modified: 2016-11-01
Does anyone have a PowerShell Script that can list a count of all objects within the per-OU in a specific domain?
0
Comment
Question by:amazon4life
4 Comments
 
LVL 6

Expert Comment

by:sAMAccountName
ID: 41850287
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
 
LVL 12

Expert Comment

by:Dustin Saunders
ID: 41850289
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
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 41850292
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
 
LVL 7

Expert Comment

by:Senior IT System Engineer
ID: 41851759
That is wonderful Richard :-)
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question