top of page

PowerShell | Get-ADOrganizationalUnit

To gather information by Organization Unit (OU) in Active Directory using PowerShell, you can use the Get-ADOrganizationalUnit cmdlet along with other Active Directory cmdlets like Get-ADUser, Get-ADComputer, etc. Below are some examples to help you get started:

Powershell Typing Keyboard
PowerShell Script Searchbase by OU

<#
Summary:  
          Get list of OU's one level down from declared parent 
          Loop through items in Var
          Get list of users in each OU, Select Name,Enabled
          Export Group results of each OU to unique file 
          
          Note: Might want to add -Recursive if there are more sub OU's

​

Author:   Scott Head
Date:     05/09/2022
Version:  1.0 
#>


$OUINFO=Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase 'OU=Employees,OU=Accounts,DC=YourDomain,DC=net' -SearchScope OneLevel | Select Name,DistinguishedName | Export-csv C:\temp\OU-List.csv -NoTypeInformation

​

Foreach($OU in $OUINFO){

    Get-ADUser -Properties * -SearchBase $ou.DistinguishedName  -Filter {(Enabled -eq $True)} | Select Name,enabled | Export-csv C:\temp\$($OU.Name).csv -NoTypeInformation     

}
 

bottom of page