You can help the contents reach more people by sharing on social media.



Category: Windows Powershell
Fırat Boyan 23.12.2021 0

Listing contents of Active Directory Organization Units with powershell

Active Directory Organization Units (OUs) are objects created to organize users, groups or computers in a Domain. It is used to group AD objects to meet the needs of the organization and to facilitate management (especially Group Policy).
I will mention about the Active Directory Organization Unit (OU) structure and how to list how many User and Computer accounts in an Organization Unit (OU) with the help of Powershell Scripts In this essay.

It is possible for you to see your current Active Directory structure and how many user objects are stored in each OU by using the following command.

Get-ADOrganizationalUnit -Properties CanonicalName -Filter * | Sort-Object CanonicalName |
ForEach-Object {
[pscustomobject]@{
Name = Split-Path $_.CanonicalName -Leaf
CanonicalName = $_.CanonicalName
UserCount = @(Get-AdUser -Filter * -SearchBase $_.DistinguishedName -SearchScope OneLevel).Count 
}}

Organization Unit

You can see your Active Directory structure and how many user and computer objects are stored in an OU by using the following command.

$results = Get-ADOrganizationalUnit -Properties CanonicalName -Filter * | Sort-Object CanonicalName |
ForEach-Object {
[pscustomobject]@{
Name = Split-Path $_.CanonicalName -Leaf
CanonicalName = $_.CanonicalName
UserCount = @(Get-AdUser -Filter * -SearchBase $_.DistinguishedName -SearchScope OneLevel).Count
}}

Organization Unit

You can take a printout of your Active Directory structure including how many user objects are stored in an OU to a TXT or CSV under the C:\ directory by using the following command.

$results = Get-ADOrganizationalUnit -Properties CanonicalName -Filter * | Sort-Object CanonicalName |
ForEach-Object {
[pscustomobject]@{
Name = Split-Path $_.CanonicalName -Leaf
CanonicalName = $_.CanonicalName
UserCount = @(Get-AdUser -Filter * -SearchBase $_.DistinguishedName -SearchScope OneLevel).Count
ComputerCount = @(Get-AdComputer -Filter * -SearchBase $_.DistinguishedName -SearchScope OneLevel).Count
}}
$results | Out-File C:\Export_User.txt -Encoding UTF8

Organization Unit
Organization Unit

You can take a printout of your Active Directory structure including how many user and computer objects are stored in an OU to a TXT or CSV under the C:\ directory by using the following command.

$results = Get-ADOrganizationalUnit -Properties CanonicalName -Filter * | Sort-Object CanonicalName |
ForEach-Object {
[pscustomobject]@{
Name = Split-Path $_.CanonicalName -Leaf
CanonicalName = $_.CanonicalName
UserCount = @(Get-AdUser -Filter * -SearchBase $_.DistinguishedName -SearchScope OneLevel).Count
ComputerCount = @(Get-AdComputer -Filter * -SearchBase $_.DistinguishedName -SearchScope OneLevel).Count
}}
$results | Out-File C:\Export_User_PC.txt -Encoding UTF8

Organization Unit
Organization Unit

I hope it benefits...
 


You may submit your any kind of opinion and suggestion and ask anything you wonder by using the below comment form.


Author: Fırat Boyan

My name is Fırat Boyan. I was born in Alanya, which is one of the counties of the Antalya city, in 1985. I am a Senior System Engineer, Microsoft Certified Trainer (MCT) and a freelance Sworn Translator from English into Turkish and from Turkish into English affiliated with a Notary Office.  I have been living in Istanbul since 2008 and providing service in the field of Information Technologies for 18 years. I currently work for Data Market as a Senior Cloud Engineer and I have been providing System and Network trainings as a Microsoft Certified Trainer (MCT) affiliated with Bilge Adam, which renders trainings in the field of Information Technologies. Besides, I provide IT consulting services for corporate companies as well. Please visit the page About Me to get more detailed information about me and to review the Microsoft certifications I have.

COMMENTS
No comment made for this video yet! Be the first to make comment.
You may submit your any kind of opinion and suggestion and ask anything you wonder by using the below comment form.


You may type 750 characters.
Please, enter the verification code with UPPER-CASE letters.
* Comments are published after being approved.
* E-mail is required for comment approval notification, not published.