积极答复者
批量导出AD中所有组成员

问题
答案
-
您好,
根据我的研究,建议可以尝试看看下面的脚本是否满足您的需要:
Get-ADGroup -Filter * -SearchBase 'OU=Group,DC=gawcap,DC=com,DC=cn' | ForEach-Object { $groupName = $_.Name Get-ADGroupMember -Identity $groupName | Select-Object @{Name = 'GroupName'; Expression = {$groupName}}, Name | Group-Object GroupName | Select-Object @{Name = 'GroupName'; Expression = {$_.Name}}, @{Name = 'Members'; Expression = {($_.Group.Name | Out-String).Trim()}} } | Export-Csv -Path C:\membership.csv -NoTypeInformation
输出的CSV文件如下图:
如果需要修改脚本,请随时通知我。
此致
AlbertPlease remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com- 已标记为答案 Barry Zhou 2018年1月24日 4:48
全部回复
-
您好,
根据我的研究,建议可以尝试看看下面的脚本是否满足您的需要:
Get-ADGroup -Filter * -SearchBase 'OU=Group,DC=gawcap,DC=com,DC=cn' | ForEach-Object { $groupName = $_.Name Get-ADGroupMember -Identity $groupName | Select-Object @{Name = 'GroupName'; Expression = {$groupName}}, Name | Group-Object GroupName | Select-Object @{Name = 'GroupName'; Expression = {$_.Name}}, @{Name = 'Members'; Expression = {($_.Group.Name | Out-String).Trim()}} } | Export-Csv -Path C:\membership.csv -NoTypeInformation
输出的CSV文件如下图:
如果需要修改脚本,请随时通知我。
此致
AlbertPlease remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com- 已标记为答案 Barry Zhou 2018年1月24日 4:48
-
您好,
要支持中文的话需要在Export-Csv命令中添加-Encoding Unicode参数。
此致
AlbertPlease remember to mark the replies as an answers if they help.
If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com