locked
Get-AdGroup expression RRS feed

  • Question

  • Hi all,

    I've got the following powershell code to get the groups name, mail field, description and members.

    Get-ADGroup -Filter * -SearchBase "OU=EXAMPLE,DC=MYDOMAIN,DC=COM" -Properties Name, Description, Member, mail| select mail, Name, Description, @{name=’Members’; expression= { ($_.member | % {(Get-ADObject $_).Name }) -join “,” }}

    But instead of the members name, I need the e-mail (mail) attribute or another attribute (example cn or displayname).

    I tried the following code (changed Get-ADObject $_).Name  to Get-ADObject $_).mail), but this result in empty results for e-mail:

    Get-ADGroup -Filter * -SearchBase "OU=EXAMPLE,DC=MYDOMAIN,DC=COM" -Properties Name, Description, Member, mail| select mail, Name, Description, @{name=’Members’; expression= { ($_.member | % {(Get-ADObject $_).mail }) -join “,” }}

    Could anybody help me to solve this?

    Thanks.

    Best,

    Tuesday, September 3, 2019 12:12 PM

Answers

  • Hi,

    Get-ADObject wont bring back what you are looking for, mail attribute in your case.

    Try to change your calculated property "Members" and call Get-Aduser, that should give you all the properties you need for each user.

    Get-ADGroup -Filter * -SearchBase "CN=SomeGroupName,DC=Lab,DC=local" -Properties Name, Description, Member | 
    Select-Object Name, Description, 
    @{name=’Members’; expression= { ($_.member | % {(Get-ADUser $_ -Properties mail).mail }) -join “,” }}

    Cheers,

    Sok.

    • Proposed as answer by Stoyan ChalakovMVP Wednesday, September 4, 2019 11:23 AM
    • Marked as answer by RoydR Wednesday, September 4, 2019 11:48 AM
    Wednesday, September 4, 2019 10:00 AM
  • The Get-ADGroup cmdlet does not expose the mail attribute, unless it is requested with the -Properties parameter.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Proposed as answer by Stoyan ChalakovMVP Wednesday, September 4, 2019 11:23 AM
    • Marked as answer by jrv Wednesday, September 4, 2019 11:27 AM
    Tuesday, September 3, 2019 1:45 PM

All replies

  • You can try with attribut: EmailAddress

    Get-ADUser -Filter * -Properties DisplayName, EmailAddress, Title | select DisplayName, EmailAddress, Title


    Vote or mark as answer if you think useful


    • Edited by F.ABASSI Tuesday, September 3, 2019 12:14 PM
    • Marked as answer by jrv Wednesday, September 4, 2019 11:27 AM
    • Unmarked as answer by jrv Wednesday, September 4, 2019 11:27 AM
    Tuesday, September 3, 2019 12:14 PM
  • The Get-ADGroup cmdlet does not expose the mail attribute, unless it is requested with the -Properties parameter.

    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Proposed as answer by Stoyan ChalakovMVP Wednesday, September 4, 2019 11:23 AM
    • Marked as answer by jrv Wednesday, September 4, 2019 11:27 AM
    Tuesday, September 3, 2019 1:45 PM
  • Thanks Richard, but how do I use the -Properties in the expression? Don't get it to work.

    Wednesday, September 4, 2019 5:44 AM
  • Hi,

    Get-ADObject wont bring back what you are looking for, mail attribute in your case.

    Try to change your calculated property "Members" and call Get-Aduser, that should give you all the properties you need for each user.

    Get-ADGroup -Filter * -SearchBase "CN=SomeGroupName,DC=Lab,DC=local" -Properties Name, Description, Member | 
    Select-Object Name, Description, 
    @{name=’Members’; expression= { ($_.member | % {(Get-ADUser $_ -Properties mail).mail }) -join “,” }}

    Cheers,

    Sok.

    • Proposed as answer by Stoyan ChalakovMVP Wednesday, September 4, 2019 11:23 AM
    • Marked as answer by RoydR Wednesday, September 4, 2019 11:48 AM
    Wednesday, September 4, 2019 10:00 AM
  • Hi,

    Get-ADObject wont bring back what you are looking for, mail attribute in your case.

    Try to change your calculated property "Members" and call Get-Aduser, that should give you all the properties you need for each user.

    Get-ADGroup -Filter * -SearchBase "CN=SomeGroupName,DC=Lab,DC=local" -Properties Name, Description, Member | 
    Select-Object Name, Description, 
    @{name=’Members’; expression= { ($_.member | % {(Get-ADUser $_ -Properties mail).mail }) -join “,” }}

    Cheers,

    Sok.

    That's works. Thank you very much Sok. Best, Roy
    Wednesday, September 4, 2019 11:49 AM