Search code examples
powershellactive-directoryget-aduser

Active Directory - How to retrieve information from the otherpager property array


A colleague put an information in the otherPager property of our active directory. I must retrieve this information. Im am using this code

Import-Module ActiveDirectory
Get-ADUSER -Filter * -properties otherPager | Select-Object -Property Name, Surname, UserPrincipalName, {$_.otherPager}[0]  | Sort-Object Name | Export-Csv -Path "\\srv-qlik\e\Datawarehouse\autres sources\Gestion des droits\Active_directory_users.csv" -Encoding Default -NoTypeInformation

otherPager property outputs as Microsoft.ActiveDirectory.Management.ADPropertyValueCollection in the csv. This is not what I expected.

I search other the internet and found out otherPager property consists in an array, but no information on how to access its elements. In fact i'd just need the first element of this array.

Can you help ?


Solution

  • First problem with your updated code is that also the EmailAddress is not returned by default and you need to specify that in parameter -Properties too.

    Second problem I think is where you set the output path for the resulting CSV file. If the path is set on the E drive of the server, you need to put a dollar sign there: \\srv-qlik\e$\Datawarehouse\autres sources\Gestion des droits\Active_directory_users.csv

    Try

    Import-Module ActiveDirectory
    
    $outputFile = '\\srv-qlik\e$\Datawarehouse\autres sources\Gestion des droits\Active_directory_users.csv'
    Get-ADUser -Filter * -Properties otherPager, EmailAddress | 
    Select-Object Name, Surname, UserPrincipalName, EmailAddress,
                  @{Name='test'; Expression = {@($_.otherPager)[0]}} |
    Sort-Object Name | 
    Export-Csv -Path $outputFile -Encoding Default -NoTypeInformation