问题
When i open the export below in excel, all i can see for MemberOf is System.String[]. How can i show each member with the name, description, userprincipalname next to it?
$Accounts | Get-QADUser | ft name, description, UserPrincipalName, memberOf | Export-Csv C:\Temp\Useraccounts.csv
回答1:
Try this:
$Accounts | Get-QADUser | select name, description, UserPrincipalName, @{ n="memberof"; e={ $_.memberof }} | Export-Csv -NoTypeInformation .\file.csv
Some info for 'calculated property' here
Some info for 'why-can-t-i-pipe-format-table-to-export-csv-and-get-something-useful'
回答2:
Join the group names and use Select-Object
instead of Format-Table
before you export to csv:
$Accounts | Get-QADUser | Select-Object Name,Description,UserPrincipalName,@{ n="memberOf"; e={ $_.memberOf -join ';' }} | Export-Csv ...
来源:https://stackoverflow.com/questions/9906583/powershell-displaying-array-data-next-to-string-data