AD Secretary and seeAlso attribute - CSV

Thanks. anything you find will be helpful. Its so close.

Learning more as we go so thank you for that as well

OK, if I got it right there are one or more DistinguishedNames in the attribute secretary, right?

Then something like this should work:

$OUName = "OU=Here"
$CSVName = "C:\Export.csv"

$UserList = 
    Get-QADUser -SearchRoot $OUName -SizeLimit 0 -IncludedProperties Secretary
    
$Report = 
foreach ($User in $UserList ) {
    foreach ($Secretary in $User.secretary ) {
        $ADSecretary = Get-QADUser -Identity $Secretary -IncludedProperties firstname-lastname-display 
        [PSCustomObject]@{
            'Employee Initals' = $User.SamAccountName
            'Secretary'        = $ADSecretary.'firstname-lastname-display'
        }
    }
}

$Report | 
    Export-Csv -Path $CSVName -NoTypeInformation -Force -Encoding UTF8

Thanks mate. This is mega close. So when i run the code

I changed the code to below.

 'Secretary'        = $ADSecretary.displayname

When the code runs and it exports the data as an example i see.

“Employee Initals”,“Secretary”
“te”,"Goodman, Steven "
“te”,“McFarlane, Craig”

What i need to see is

“Employee Initals”,“Secretary”
“te”,"Goodman, Steven , McFarlane, Craig "

The code as it stands right now is below.

$UserList = 
    Get-QADUser -SearchRoot $OUName -SizeLimit 0 -IncludedProperties Secretary , firstname-lastname-display
    
$Report = 
foreach ($User in $UserList ) {
    foreach ($Secretary in $User.secretary ) {
        $ADSecretary = Get-QADUser -Identity $Secretary -IncludedProperties firstname-lastname-display 
        [PSCustomObject]@{
            'Employee Initals' = $User.SamAccountName
            'Secretary'        = $ADSecretary.displayname
        }
    }
}

$Report | 
    Export-Csv -Path $CSVName -NoTypeInformation -Force -Encoding UTF8

:face_with_raised_eyebrow:

$Report = 
foreach ($User in $UserList ) {
    $SecretaryList =
    foreach ($Secretary in $User.secretary ) {
        (Get-QADUser -Identity $Secretary -IncludedProperties firstname-lastname-display).displayname
    }
    [PSCustomObject]@{
        'Employee Initals' = $User.SamAccountName
        'Secretary'        = $SecretaryList -join ', '
    }
}

Hi , No i had tried that but it was still on two lines. I have copied your full code but still the same

If I wanted to be polite I’d say “That’s V E R Y unlikely” … Are you sure you don’t use and older code version?

Start with a new PS session and remove the old CSV file before you run the new code.

1 Like

I still don’t understand why we are insisting on using the quest commands? Sure they were great when powershell was new and lacking, but now it seems like a bad choice, IMHO. :man_shrugging:

Since I cannot validate this I tend to believe it for now. :man_shrugging:t3:

But since the data comes from AD it is not necessary to get the desired information.