>我有脚本可以在OU中搜索并显示用户名,名称,AD组和描述。
$ou = 'distinguishedName of the OU'
Get-ADGroup -Filter * -SearchBase $ou -Properties Description | ForEach-Object {
foreach($member in Get-ADGroupMember $_) {
[pscustomobject]@{
SamAccountName = $member.SamAccountName
Name = $member.Name
GroupName = $_.Name
Description = $_.Description
}
}
} | Export-csv C:UsersMyUsernameDesktopNameOfMyFile.csv -NoTypeInformation
离开研究,我相信我必须使用Get-ADUser和邮件属性。
像这样:
($members in Get-ADUser $1)
Email = $1.mail
我试图更改此代码并惨遭失败。
请问有人可以帮忙吗?
如果您只查找用户对象成员资格,而不是使用Get-ADGroupMember
您可以使用Get-ADUser
查询"属性MemberOf
等于组DistinguishedName
的用户":
$ou = 'distinguishedName of the OU'
Get-ADGroup -Filter * -SearchBase $ou -Properties Description | ForEach-Object {
$params = @{
LDAPFilter = '(memberof={0})' -f $_.DistinguishedName
Properties = 'mail'
}
foreach($member in Get-ADUser @params) {
[pscustomobject]@{
SamAccountName = $member.SamAccountName
Name = $member.Name
Mail = $member.Mail
GroupName = $_.Name
Description = $_.Description
}
}
} | Export-csv C:UsersMyUsernameDesktopNameOfMyFile.csv -NoTypeInformation