I want to use Get-ADUser to pull the "info" AD attribute, expand the property named info and export the data to a csv. How do I proceed?

Zuph Elkanah 0 Reputation points
2025-05-03T22:41:44.8833333+00:00

I want to use Get-ADUser to pull the "info" AD attribute, expand the property named info and export the data to a csv. How do I proceed?

For example, when I use this command:

Get-ADUser * -Unlimited -Properties info | Select Name, info | export "c:\report\AD_User-Info.csv" -notype

The csv only has one line for the "Info" property, when there are very often more than one line in that field in an ADUC user account properties: located under the telephones [tab] / notes [field].
If I use Get-ADUser * -Unlimited -Properties info | Select -ExpandProperty info | export "c:\report\AD_User-Info.csv" -notype

I get all the lines, but I also want to match each Note/info to an AD user account property that could be "Name", "UserPrincipalName", "samAccountName", etc

Please help me accomplish this feat.

PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,924 questions
0 comments No comments
{count} votes

Accepted answer
  1. Marcin Policht 44,850 Reputation points MVP
    2025-05-03T23:18:24.87+00:00

    You're very close — the key issue is that Select -ExpandProperty info breaks the association between the info property and the user object (like Name or samAccountName). Instead, you want to keep info as part of the user object and preserve all relevant properties.

    Try the following:

    Get-ADUser -Filter * -Properties info | 
    Select-Object Name, SamAccountName, UserPrincipalName, @{Name="Info";Expression={$_.info}} |
    Export-Csv "C:\report\AD_User-Info.csv" -NoTypeInformation -Encoding UTF8
    
    • Select-Object grabs the properties you want (Name, SamAccountName, UserPrincipalName) and includes the info field as-is.
    • Using a calculated property (@{Name="Info";Expression={$_.info}}) helps ensure line breaks are preserved.
    • Export-Csv handles exporting, and using -Encoding UTF8 is optional but helps with character compatibility.

    Multi-line content (like what's stored in the "info" attribute via the "Notes" field) is stored as a single string with embedded newlines. Export-Csv will preserve those newlines, but when you open the file in Excel, you might need to enable text wrapping or open it in a text editor to see line breaks clearly.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.