List all Active Directory Organizational Unit LDAP (PS)

Purpose: Query all or some Active Directory Organisational Units and their LDAPs

Powershell has an enourmous amount of cmdlets, which can be called to do your bidding. In this scenario you want to list all your Acrive Directory Organizational Units and unleash some filters to that mass. There are many alternative ways to do this, select one of them below and have fun.

Usage: powershell.exe -ExecutionPolicy ByPass -file IT_AD_PS_GetAllOrganizationalUnits.ps1
Configuration: You can use filters to change the outcome of your query
References: Get-ADOrganizationalUnit, Export-Csv

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# *********************************************************************************
# ** Script Name: IT_AD_PS_GetAllOrganizationalUnits.ps1
# ** Created on: 04.10.2013
# ** Author: Jyri Lehtonen / http://it.peikkoluola.net
# **
# ** Purpose: Query all or some Active Directory Organisational Units
# ** Usage: powershell.exe -ExecutionPolicy ByPass -file IT_OSD_VBS_RemoveAFileFromEveryUserProfile.ps1
# **
# ** License: This program is free software: you can redistribute it and/or modify
# ** it under the terms of the GNU General Public License as published by
# ** the Free Software Foundation, either version 3 of the License, or
# ** (at your option) any later version.
# **
# ** This program is distributed in the hope that it will be useful,
# ** but WITHOUT ANY WARRANTY; without even the implied warranty of
# ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# ** GNU General Public License for more details.
# ** 
# ** History: 
# ** 1.0 / Jyri Lehtonen / 04.10.2013 / Initial version.
# *********************************************************************************
 
#Alternative way 1:
Get-ADOrganizationalUnit -LDAPFilter '(DistinguishedName=*)' -searchbase 'OU=(your ou),DC=(your domain),DC=(your domain locale)' | select-object -property DistinguishedName
 
#Alternative way 2:
Get-ADOrganizationalUnit -Filter 'Name -like "*"' | FT Name, DistinguishedName -A
 
#Alternative way 3:
Get-ADOrganizationalUnit -Filter 'Name -like "*"' | FT Name, DistinguishedName -A | Export-Csv C:\TEMP\Exported_OU_List.csv
# *********************************************************************************
# ** Script Name: IT_AD_PS_GetAllOrganizationalUnits.ps1
# ** Created on: 04.10.2013
# ** Author: Jyri Lehtonen / http://it.peikkoluola.net
# **
# ** Purpose: Query all or some Active Directory Organisational Units
# ** Usage: powershell.exe -ExecutionPolicy ByPass -file IT_OSD_VBS_RemoveAFileFromEveryUserProfile.ps1
# **
# ** License: This program is free software: you can redistribute it and/or modify
# ** it under the terms of the GNU General Public License as published by
# ** the Free Software Foundation, either version 3 of the License, or
# ** (at your option) any later version.
# **
# ** This program is distributed in the hope that it will be useful,
# ** but WITHOUT ANY WARRANTY; without even the implied warranty of
# ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# ** GNU General Public License for more details.
# ** 
# ** History: 
# ** 1.0 / Jyri Lehtonen / 04.10.2013 / Initial version.
# *********************************************************************************

#Alternative way 1:
Get-ADOrganizationalUnit -LDAPFilter '(DistinguishedName=*)' -searchbase 'OU=(your ou),DC=(your domain),DC=(your domain locale)' | select-object -property DistinguishedName

#Alternative way 2:
Get-ADOrganizationalUnit -Filter 'Name -like "*"' | FT Name, DistinguishedName -A

#Alternative way 3:
Get-ADOrganizationalUnit -Filter 'Name -like "*"' | FT Name, DistinguishedName -A | Export-Csv C:\TEMP\Exported_OU_List.csv

Leave a Reply

Your email address will not be published. Required fields are marked *


seven + one =

Post Navigation