powershell: displaying array data next to string data?

。_饼干妹妹 提交于 2019-12-25 18:35:38

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!