Hi,
Have you tried running the query with the Get-Aduser cmdlet? You can specify a base OU and it returns child objects,
If the answer is helpful, please click "Accept Answer"
# Define the path and file name for the CSV export
$ExportPath = "C:\OU-Export.csv"
# Create an array to store the OU data
$OUs = @()
# Set the FGH OU distinguished name manually
$OU = "OU=FGH,DC=FGH,DC=local"
# Get all of the child OUs of the FGH OU
$Searcher = Get-ADUser -Filter * -SearchBase $OU -Properties * | select *
foreach ($User in $Searcher) {
$UserProperties = @{
"OU" = $User.DistinguishedName
"Name" = $User.Name
"Description" = $User.description
"Email" = $User.mail
}
$OUs += New-Object PSObject -Property $UserProperties
}
# Export the array to a CSV file
$OUs | Export-Csv -Path $ExportPath -NoTypeInformation