Solved

PowerShell Script - Count OUs within a specific domain

Posted on 2016-10-19
4
44 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 5

Expert Comment

by:sAMAccountName
Comment Utility
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
Comment Utility
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 32

Accepted Solution

by:
it_saige earned 500 total points
Comment Utility
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
Comment Utility
That is wonderful Richard :-)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
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…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now