我需要提取包含 5000 多名成员的 AD 组中所有用户的姓名和手机号码。
当我以前这样做时,我只需要提取名称,此代码解决了我的问题
Get-ADGroup 'xxx' -Properties Member | Select-Object -ExpandProperty Member | Sort
Get-ADGroup "xxx" -Properties Member | Select-Object -ExpandProperty Member | Get-ADObject | Select Name | Sort Name
((Get-ADGroup "xxx" -Properties member).member).count
Get-ADGroup "xxx" -Properties Member | Select-Object -ExpandProperty Member | Get-ADObject | Select Name | Sort Name | Export-Csv C:\temp\exportmembers.csv -Encoding UTF8 -NoTypeInformation
由于组不包含“移动”属性,我不确定该如何处理。
任何帮助都将受到赞赏。
答案1
您可以使用 直接获取所有群组成员Get-ADGroupMember
,甚至包括子群组
get-adgroup 'xxxx' |Get-ADGroupMember -Recursive |
get-aduser -Properties name,mobile |sort name |select name,mobile |
Export-Csv C:\temp\exportmembers.csv -Encoding UTF8 -NoTypeInformation
对于 +5000 名成员的问题,只需将属性添加到Get-AdObject
和Select-Object
Get-ADGroup "xxx" -Properties Member | Select-Object -ExpandProperty Member |
Get-ADObject -Properties mobile | Select Name,mobile | Sort Name |
Export-Csv C:\temp\exportmembers.csv -Encoding UTF8 -NoTypeInformation