我的PowerShell脚本是这样的:
Get-ADUser -Property * -filter * | Select-Object @{Label="Member Of";Expression={
%{Get-ADPrincipalGroupMembership -Identity $_.SamAccountName | Select-Object name}
}}
输出:
Member Of --------- {@{name=XYZUsers}, @{name=GLOBAL_XYZ}, @{name=LOCAL_XYZ}, @{name=ABC_APPROVER} {@{name=XYZUsers}, @{name=GLOBAL_XYZ}, @{name=LOCAL_XYZ}, @{name=ABC_APPROVER}
我希望输出如下:
Member Of --------- XYZUsers, GLOBAL_XYZ, LOCAL_XYZ XYZUsers, GLOBAL_XYZ, LOCAL_XYZ
答案 0 :(得分:1)
我认为-ExpandProperty
的{{1}}参数可能就是您所需要的。
试试这个:
Select-Object
或者我认为你也可以简化你的代码,但我现在没有任何地方可以测试它:
Get-ADUser -property * -filter * | select-object @{Label = "Member Of";Expression = {%{Get-ADPrincipalGroupMembership -Identity $_.SamAccountName | Select-Object -ExpandProperty name}}}
答案 1 :(得分:1)
您的Select-Object
语句为您提供了包含属性name
(@{name=...}
)的自定义对象。您需要提取此属性的值(例如,通过-ExpandProperty
的{{1}}参数),然后将提取的组名称连接到字符串:
Select-Object
答案 2 :(得分:0)
get-aduser -property * -filter * | select-object @ {Label =“Member Of”; Expression = {%{Get-ADPrincipalGroupMembership -Identity $ .SamAccountName | foreach-Object {$ .name}}}}