字符串加入 select object 或 Export-Csv

String join in select object or Export-Csv

I 行将所有 365 个用户导出到 CSV:

Get-MsolUser |
    Select-Object -Property UserPrincipalName, DisplayName, Licenses,
        LastLogonTime, Country, IsLicensed, UsageLocation, UserType |
    Export-Csv -Path c:\temp5-users.csv -NoTypeInformation

Licenses 是 object 的数组。数组中的每个 object 都有一个 属性 AccountSkuId。是否可以在上面的 oneliner 中将数组连接成逗号分隔的字符串?现在它 returns 如下:

System.Collections.Generic.List`1[Microsoft.Online.Administration.UserLicense]

注意我想将许可证保留在 header 中,所以我最好的选择是它在导出部分。还是我需要制作一个 for 循环并手动执行?

根据@Ansgar 的建议,您可以按照以下方式将计算得到的 属性 集成到当前的 select 语句中并检索您要查找的属性。

Select-Object -Property UserPrincipalName, DisplayName, `
  @{name="licenses";expression={$_.licenses.accountskuid -join ";"}}, `
  LastLogonTime, Country, IsLicensed, UsageLocation, UserType |
    Export-Csv -Path c:\temp5-users.csv -NoTypeInformation