Quantcast
Channel: Directory Services forum
Viewing all articles
Browse latest Browse all 31638

AD PowerShell Script to list all OU alongwith its child OU's in a text file

$
0
0

Hi,

I am trying to get my head around a PS script which can list all the OU's (alongwith its child/grandchild OU's) in a text file.

The following script does the job halfway but the output is flat. i.e. it just lists all the OU's and nested OU's straight.

Get-ADOrganizationalUnit -Filter*|Select-Object-Property Name |Format-Table-AutoSize;

This will display a list looking something like below;

Name
----
Domain Controllers
Microsoft Exchange Security Groups
Security Groups
Domain Servers
Domain Workstations
Domain Guest Accounts
Printers
Management
Virtual Desktops
IT
Service Accounts
Users
Computers
Production Servers
SQL Servers
Web Servers

However, what I am looking for is something like this in the report.

+ Domain Controllers
                               - Virtual

                                           - 2008 R2

                                           - 2012

                               - Physical

Microsoft Exchange Security Groups
Security Groups
Domain Servers
Domain Workstations
Domain Guest Accounts
Printers
Management
Virtual Desktops
IT
Service Accounts
Users
Computers
Production Servers
SQL Servers
Web Servers


HA


Viewing all articles
Browse latest Browse all 31638

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>