0

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 ?

  • use otherPager[0] – jdweng Mar 30 '23 at 09:45
  • Doesn't work, outputs a column otherPager[0] with no value on test AD user record. Before you ask, yes there is a value in for the test user in the otherPager property. – Philippe MERLE Mar 30 '23 at 09:52
  • Try a "calculated property" - see https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_calculated_properties?view=powershell-7.3#select-object - something like ```Select-Object ..., @{"n"="PagerNo"; "e"={$_.otherPager[0]}}, ...``` should do the trick (error handling aside)... – mclayton Mar 30 '23 at 10:15
  • KO. Although calculated property outputs a custom column, it has no value in it. – Philippe MERLE Mar 30 '23 at 10:37
  • Replacing select-object by format-table works ... ok so the problem could be more on buiding correctly the select-object statement – Philippe MERLE Mar 30 '23 at 11:14
  • Attribute `otherPager` is not a property that gets returned in the default subset of properties of Get-ADUser. You need to ask for it using `Get-ADUser -Filter * -Properties otherPager` Without specifying any extras, Get-ADUser returns these properties: `DistinguishedName, Enabled, GivenName, Name, ObjectClass, ObjectGUID, SamAccountName, SID, Surname, UserPrincipalName` – Theo Mar 30 '23 at 11:15
  • You are right, I relaunched the request (and updated the post) but still no value for otherPager. Problem is with proceeding with csv export, `Format-Table Name, @{name='test';expr={$_.otherPager[0]}} -A ` works but can't have a proper csv with that. That's why i am looking for a solution with select-object – Philippe MERLE Mar 30 '23 at 11:36
  • Just to sanity check, try this as the expression: ```$_.otherPager | ConvertTo-Json```. That’ll let you see what’s actually inside the property and might give a clue to what the problem is… – mclayton Mar 30 '23 at 11:42
  • ``` "otherPager": [ "basetech:11092-btercpg:1275-sg:1161" ] ``` – Philippe MERLE Mar 30 '23 at 12:19
  • Solution found and post edited. Thank you very much everybody – Philippe MERLE Mar 30 '23 at 12:59

1 Answers1

0

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
Theo
  • 57,719
  • 8
  • 24
  • 41
  • Sorry, did not read your post In time but I came out to a similar solution. Edited my post with it. No issue with the export path, it works as expected without the '$'. thank you very much – Philippe MERLE Mar 30 '23 at 12:58