简体   繁体   中英

Display members of a SC-group with filtered results

I'm trying to make a script on how to make a simple get-ADGroupMember but with several displayed results. One which the above cmdlet can display, and that is the 'mail'-attribute.

Get-ADGroupMember -identity "group-name one" -Recursive | Get-ADUser -property DisplayName | Select Name,DisplayName,mail

One simple solution would be to use the code below, as its displays the results I want all together (I have removed sensitive info in the output). As I'm going to present this information to a customer, I want a more "clean" look on the output, one which the above code could supply (user friendly). The first output works fine if not for the fact that it doesn't show the mail attribute.

Get-ADGroupMember -identity "avd-Barn- och utbildningskontoret" -Recursive | Get-ADUser -property mail

DistinguishedName : 
Enabled           : True
GivenName         : Lisa
mail              : 
Name              : 
ObjectClass       : user
ObjectGUID        : 98cb2a62
SamAccountName    : 
SID               : S-1-5-21
Surname           : surname
UserPrincipalName : 

Is there a way to this?

This gave me what I wanted. This way, I can add several groups at once as well if needed in the future.

$arrResults = @()
foreach($varGroup in (Get-ADGroupMember -identity "groupname")){
foreach($varUser in (Get-ADUser $varGroup -properties mail | select SamAccountName, mail)){
foreach($varUsor in (Get-ADUser $varGroup -properties DisplayName | select DisplayName)){
$objResult = New-Object PSobject
$objResult | Add-Member -membertype NoteProperty -Name "SamAccountName" -Value $varUser.SamAccountName
$objResult | Add-Member -MemberType NoteProperty -Name "Mail" -Value $varUser.mail
$objResult | Add-Member -Membertype NoteProperty -Name "DisplayName" -Value $varUsor.DisplayName
$arrResults += $objResult
}
}
}
$arrResults

最简单的方法是:

Get-ADGroupMember -Identity "group-name one" -Recursive | Get-ADUser -properties DisplayName,mail | Select Name,DisplayName,mail

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM