locked
How to use Get-ADGroupMember RRS feed

  • Question

  • In this script below you can get useful information from each object you are querying. My question is for the code below, where can you get a list of attributes that you can do this with?  For instance powershell knows what .name means and it knows what .samaccountname is.  What else can I do this with? Could I use .extensionAttribute1 and if not where is a list of these types of attributes?

    Foreach ($Group in $Groups) {

      $Arrayofmembers = Get-ADGroupMember -identity $Group -recursive | select name,samaccountname

      foreach ($Member in $Arrayofmembers) {
        $Record."Group Name" = $Group.name
        $Record."Name" = $Member.name
        $Record."UserName" = $Member.samaccountname
        $objRecord = New-Object PSObject -property $Record
        $Table += $objrecord

      }
    }


    Tuesday, February 9, 2016 5:13 PM

Answers

  • Get-ADGroupMember does not have a -Properties parameter that you can use to return additional properties. You can, however, pipe those results into Get-ADUser to return additional properties. See this for details:

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


    EDIT: In short, you can specify a wildcard with -Properties (for cmdlets that have this parameter available) to return all available properties. Pipe that into Get-Member to see the list.


    Get-ADUser tester1 -Properties * | Get-Member


    • Edited by Mike Laughlin Tuesday, February 9, 2016 5:51 PM
    • Proposed as answer by Richard MuellerMVP Tuesday, February 9, 2016 6:39 PM
    • Marked as answer by Yan Li_ Thursday, February 25, 2016 2:43 AM
    Tuesday, February 9, 2016 5:49 PM
  • Hi pwrshellrn,

    welcome to Technet :)

    you can check the properties of any object, by using the Get-Member cmdlet (making it one of the most powerful cmdlets in all of PowerShell). Example:

    Get-ADGroupMember -Identity $Group | Get-Member

    Now you will notice, that the output of Get-ADGroupMember does not have the extensionattribute1 property. However, many ad cmdlets allow you to specify which properties to load. Let's take a peek at Get-ADGroupMember:

    Get-Help Get-ADGroupMember -Detailed

    Reading this through, we will realize that it does not have a way to request more information. However, there is a cmdlet in AD that can help us here. You'd probably have a hard time finding it on your own, so I'll tell ya:

    Get-ADObject

    With that, we can specify any properties we want to load (using the -Properties parameter). This allows for this syntax:

    Get-ADGroupMember -Identity $Group | Get-ADObject -Properties extensionAttribute1 | select name,extensionattribute1

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Proposed as answer by Richard MuellerMVP Tuesday, February 9, 2016 6:40 PM
    • Marked as answer by Yan Li_ Thursday, February 25, 2016 2:43 AM
    Tuesday, February 9, 2016 5:50 PM

All replies

  • Get-ADGroupMember does not have a -Properties parameter that you can use to return additional properties. You can, however, pipe those results into Get-ADUser to return additional properties. See this for details:

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


    EDIT: In short, you can specify a wildcard with -Properties (for cmdlets that have this parameter available) to return all available properties. Pipe that into Get-Member to see the list.


    Get-ADUser tester1 -Properties * | Get-Member


    • Edited by Mike Laughlin Tuesday, February 9, 2016 5:51 PM
    • Proposed as answer by Richard MuellerMVP Tuesday, February 9, 2016 6:39 PM
    • Marked as answer by Yan Li_ Thursday, February 25, 2016 2:43 AM
    Tuesday, February 9, 2016 5:49 PM
  • Hi pwrshellrn,

    welcome to Technet :)

    you can check the properties of any object, by using the Get-Member cmdlet (making it one of the most powerful cmdlets in all of PowerShell). Example:

    Get-ADGroupMember -Identity $Group | Get-Member

    Now you will notice, that the output of Get-ADGroupMember does not have the extensionattribute1 property. However, many ad cmdlets allow you to specify which properties to load. Let's take a peek at Get-ADGroupMember:

    Get-Help Get-ADGroupMember -Detailed

    Reading this through, we will realize that it does not have a way to request more information. However, there is a cmdlet in AD that can help us here. You'd probably have a hard time finding it on your own, so I'll tell ya:

    Get-ADObject

    With that, we can specify any properties we want to load (using the -Properties parameter). This allows for this syntax:

    Get-ADGroupMember -Identity $Group | Get-ADObject -Properties extensionAttribute1 | select name,extensionattribute1

    Cheers,
    Fred


    There's no place like 127.0.0.1

    • Proposed as answer by Richard MuellerMVP Tuesday, February 9, 2016 6:40 PM
    • Marked as answer by Yan Li_ Thursday, February 25, 2016 2:43 AM
    Tuesday, February 9, 2016 5:50 PM