Solved

PowerShell Script - Count OUs within a specific domain

Posted on 2016-10-19
4
89 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 13

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 34

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 8

Expert Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

734 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