我感兴趣的是将特定通讯组的所有成员导出到.csv
文件中,并且还列出了Active Directory中每个用户的“职位”字段。
我有点理解Get-DistributionGroup
的用法才能完成此任务的第一部分,但是我又如何查询和导出该组中每个用户的“职位”字段?
答案 0 :(得分:0)
您确实需要进行Tour的堆栈溢出。无论如何都会帮助您,因为我们在这里很不错。
$DLAlias = "Your DL list"
$DL = Get-DistributionGroupMember "$DLAlias"
$output = Foreach($user in $DL){
Get-ADUser $User.Name -Properties SamAccountName, mail, Description | select SamAccountName, mail, Description
}
$output | export-csv "C:\Temp\$DLAlias Members.csv" -NoTypeInformation
答案 1 :(得分:0)
输入通讯组列表组的名称,以及导出文件的目录:
$ExportDirectory = "\\Path\to\folder"
$DistributionList = "Name of Distr List"
# Get Members, pipe to filter by User objects, pipe to get AD User objects, store in members variable
$Members = $(Get-DistributionGroupMember -Identity "$DistributionList") |
Where-Object { $_.ObjectClass -eq "User" } |
Foreach { Get-ADUser $_.SAMAccountName -Properties Title }
# Output members of list to CSV
$Members | Export-Csv "$ExportDirectory\$DistributionList.csv" -NoTypeInformation
打开文件后,您应该看到属于通讯组的用户对象。