AD DN Attribute - System.Object{}

Guys, I am having some issues with this script. I have removed all the working attributes from it , just leaving me with two. both are DN AD attributes for Secretary and seeAlso

If each attribute has a single entry they seem to display the first name and last name but if they contain multiple entries then i get a System.Object{} in the CSV export.

Any ideas , i am pulling my hair out LOL…

Import-Module ActiveRolesManagementShell
Connect-QADService -Service “AR-Server-Name-Here” -Proxy
$OUName = “OU_Name_Here”
$CSVName = “C:\Export.csv”

$Report = @()

foreach ($user in (Get-QADUser -SearchRoot $OUName -SizeLimit 0 -IncludedProperties Secretary , seealso )) {

try {
   $Secretary = Get-QADUser $user.Secretary -ErrorAction Stop
    $sName = "$($Secretary.FirstName) $($Secretary.LastName)"
    $sPhone = $Secretary.homephone
}
catch {
    $sName = ''
}

try {
$SeeAlso = Get-QADUser $user.SeeAlso -ErrorAction Stop
$sSeeAlso = “$($SeeAlso.FirstName) $($SeeAlso.LastName)”

}
catch {
    $sSeeAlso = ''
}


$Report += New-Object PSObject -Property @{
   'SamAccountName' = $user.SamAccountName 
   'Secretary' = $sName
   'seeAlso' = $sSeeAlso
 
}

}
$Report | Select-Object SamAccountName , Secretary , SeeAlso | Export-Csv -path $CSVName -NoTypeInformation -Force -Encoding UTF8

Since you did not format your code as code here in the forum I don’t like to digg into it.

Assuming you actually see System.Object[] instead of System.Object{} this usually indicates an array instead of a single element. If you want to export it as single element you may concatenate it with the -join operator.

Something like this …

$Array = 'John', 'George', 'Paul', 'Ringo'

If you output this it looks like this:

PS:>$Array        
John
George
Paul
Ringo

If you join it it looks like this:

PS:>$Array -join ', '
John, George, Paul, Ringo