none
How does Powershell Get multiple specified user properties using the get-aduser filter RRS feed

  • Question

  • How does Powershell Get multiple specified user properties using the get-aduser filter

    I need to get the email addresses of users a, b, c ,It needs to be obtained once in -fiter。

    Get-ADUser -Filter 'SamAccountName -like “a” -and Mail -like “ *”'

    Or some other method.

    Second question

    $DN = "ou=chx,DC=hpi,DC=com,DC=cn"
    $1 = "aa","bb"
    ########################################
    Get-ADUser -SearchBase $DN -Filter "SamAccountName -like '$1[0]'"

    The user cannot be obtained using this method and how to implement it.

    Friday, November 15, 2019 1:32 PM

Answers

  • Get-AdUser -Filter "SamAccountName -eq 'a'" -Properties <properties to get>
    
    Get-ADUser -SearchBase $DN -Filter "SamAccountName -eq '$($1[0])'"
    

    help Get-AdUser -online


    \_(ツ)_/

    • Marked as answer by Zhen_Chen Saturday, November 16, 2019 5:12 PM
    Friday, November 15, 2019 1:48 PM
    Moderator
  • " I need to get the email addresses of users a, b, c ,It needs to be obtained once in -fiter。"

    Get-ADUser -Filter "SamAccountName -eq 'a' -or SamAccountName -eq 'b' -or SamAccountName -eq 'c'"

    What you are asking is pretty vague. You cannot get multiple users in one command except with a wildcard but you can use multiple wildcards if you "OR" them together.


    \_(ツ)_/

    • Marked as answer by Zhen_Chen Saturday, November 16, 2019 5:12 PM
    Friday, November 15, 2019 1:51 PM
    Moderator
  • To retrieve email addresses, specify the EmailAddress property with the -Properties parameter:

    Get-ADUser -SearchBase $DN -Filter "SamAccountName -eq '$($1[0])'" -Properties EmailAddress

    Certain default properties, such as SAMAccountName and DistinguishedName, are always retrieved. But extended properties, such as EmailAddress, are only retrieved when requested with -Properties. Details here:

    https://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser-default-and-extended-properties.aspx


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Marked as answer by Zhen_Chen Saturday, November 16, 2019 5:12 PM
    Friday, November 15, 2019 2:14 PM

All replies

  • Get-AdUser -Filter "SamAccountName -eq 'a'" -Properties <properties to get>
    
    Get-ADUser -SearchBase $DN -Filter "SamAccountName -eq '$($1[0])'"
    

    help Get-AdUser -online


    \_(ツ)_/

    • Marked as answer by Zhen_Chen Saturday, November 16, 2019 5:12 PM
    Friday, November 15, 2019 1:48 PM
    Moderator
  • " I need to get the email addresses of users a, b, c ,It needs to be obtained once in -fiter。"

    Get-ADUser -Filter "SamAccountName -eq 'a' -or SamAccountName -eq 'b' -or SamAccountName -eq 'c'"

    What you are asking is pretty vague. You cannot get multiple users in one command except with a wildcard but you can use multiple wildcards if you "OR" them together.


    \_(ツ)_/

    • Marked as answer by Zhen_Chen Saturday, November 16, 2019 5:12 PM
    Friday, November 15, 2019 1:51 PM
    Moderator
  • To retrieve email addresses, specify the EmailAddress property with the -Properties parameter:

    Get-ADUser -SearchBase $DN -Filter "SamAccountName -eq '$($1[0])'" -Properties EmailAddress

    Certain default properties, such as SAMAccountName and DistinguishedName, are always retrieved. But extended properties, such as EmailAddress, are only retrieved when requested with -Properties. Details here:

    https://social.technet.microsoft.com/wiki/contents/articles/12037.active-directory-get-aduser-default-and-extended-properties.aspx


    Richard Mueller - MVP Enterprise Mobility (Identity and Access)

    • Marked as answer by Zhen_Chen Saturday, November 16, 2019 5:12 PM
    Friday, November 15, 2019 2:14 PM