Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PowerShell Script - Count OUs within a specific domain

Posted on 2016-10-19
4
Medium Priority
?
234 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 14

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 35

Accepted Solution

by:
it_saige earned 2000 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 8

Expert Comment

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

Featured Post

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

824 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