Function Get-ADOrganizationalUnitOneLevel {
param($Path_ADOUOL, $Server_ADOUOL)#, $OUHash_ADOUOL)
#write-output "Path_ADOUOL '$Path_ADOUOL'"
#write-output "Path_ADOU '$Path_ADOU'"
#write-output "Server_ADOUOL '$Server_ADOUOL'"
#write-output "Server_ADOU '$Server_ADOU'"
Get-ADOrganizationalUnit -Filter * -Properties name, distinguishedName, gPLink, gPOptions -SearchBase $Path_ADOUOL -SearchScope OneLevel | Sort-Object Name | ForEach-Object {
#$script:OUHash.Add($_.DistinguishedName,$script:Counter++)
## HERE Create New PS Object and then output that to cli so it will be caught by the original.
$DistinguishedName = $_.DistinguishedName
$gPLink = $_.gPLink
$gPOptions = $_.gPOptions
## Regular outoput for now
$DistinguishedName
$gPLink
$gPOptions
Get-ADOrganizationalUnitOneLevel -Path $_.DistinguishedName
}
}
Function Get-ADOrganizationalUnitSorted {
param($Server_ADOU)
$DomainRoot = (Get-ADDomain -Server $Server_ADOU).DistinguishedName
#write-output "DomainRoot '$DomainRoot'"
#write-output "Server_ADOU '$Server_ADOU'"
#$script:Counter = 1
#$script:OUHash = @{$DomainRoot=0}
Get-ADOrganizationalUnitOneLevel $DomainRoot $Server_ADOU $OUHash
#$OUHash
}
$Server = 'sub.domain.com'
$SortedOUs = Get-ADOrganizationalUnitSorted $Server
$SortedOUs
Also, did you mean child OUs? This is automatic if inheritance block is not enabled or enforce is configured on GPO