选择对象或导出 CSV 中的字符串联接



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

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

Licenses是一个对象数组。数组中的每个对象都有一个属性AccountSkuId。是否可以在上面的单行中将数组连接成逗号分隔的字符串?现在它返回以下内容:

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

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

为了基于@Ansgar的建议,下面介绍了如何将计算属性集成到当前 select 语句中并检索要查找的属性。

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

最新更新