如何仅使用CN名称正确导出memberof到CSV

时间:2018-01-04 17:44:55

标签: powershell

Get-ADOrganizationalUnit -Filter * |Where-Object {$_.name -like "Users"}|ForEach-Object { Get-ADUser -SearchBase $_.DistinguishedName -Filter * -Properties *}|select name, memberof|export-csv .\output.csv

我将Microsoft.ActiveDirectory.Management.ADPropertyValueCollection作为memberof的输出

2 个答案:

答案 0 :(得分:0)

Get-ADOrganizationalUnit -Filter * |Where-Object {$_.name -like "Users"}|ForEach-Object { Get-ADUser -SearchBase $_.DistinguishedName -Filter * -Properties *}|select name, @{n='memberof'; e={$_.Memberof -join '~'}} | export-csv .\output.csv

我决定使用代字号分隔MemberOf,因为问题中没有关于你实际效果的详细信息。

答案 1 :(得分:0)

这有效

Get-ADOrganizationalUnit -Filter *|Where-Object {$_.name -like "Users" -and "No GPO" }|
ForEach-Object { Get-ADUser -SearchBase $_.DistinguishedName -Filter * -Properties *}|
select Name, Office, @{n=’MemberOf’; e= {( $_.memberof | % { (Get-ADObject $_).Name }) -join “,” }}|
export-csv C:\Member_list_Output.csv  -NoTypeInformation