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 theinfo
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