![](/img/trans.png)
[英]PowerShell script to create CSV file listing all groups in OU and # of members in each group
[英]Powershell Script to Export All Groups and Members Assigned for a given OU to a CSV
我正在尝试导出给定OU的所有组和分配的成员(如果有)。 如何包含没有成员的组?
Get-ADGroup -Properties * -Filter * -SearchBase "OU=BI-Security,OU=BH-Security Groups,DC=bh,DC=intra" | Foreach {
$Group = $_
Get-ADGroupMember -Id $Group | `
select @{Expression={$Group.Name};Label="Group Name"},Name | `
Export-CSV C:\Scripts\BIGroups.CSV -NoTypeInformation -append
}
提前致谢。
使用Select-Object
在计算的属性内调用Get-ADGroupMember
:
$groups = Get-ADGroup -Filter * -SearchBase 'OU=BI-Security,OU=BH-Security Groups,DC=bh,DC=intra'
$groups |Select-Object @{Expression={$_.Name};Label='Group Name'},@{Expression={@(Get-ADGroupMember -Identity $_|Select -Expand Name) -join ';'};Label='Name'} | Export-CSV C:\Scripts\BIGroups.CSV -NoTypeInformation -append
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.