Get-adgroupmember returning to much

This is a little script that gets the members of an AD group. It works and does want I want it to. Further down the line I would like to do more with the data I get from this script. However each element of the array looks like :


Is there a way to get rid of the SamAccountName part so it only returns the username? Script is below, and forgive me if my post is a mess still figuring things out here.

$email = get-adgroupmember -identity “GenericGroup” | Select-object -Property SamAccountName

$array = @($email)

Welcome to the forum. :wave:t4:

Please do not post images of code or console output. Instead post the plain text and format it as code.

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in <---- Click :point_up_2:t4: :wink:

Of course. It depends on what you want to achieve. But the additional variable definition you use is unnecessary anyway. The variable you create with the AD query already is an array. And since we work with rich and powerful objects instead of stupid boring text in PowerShell you usually have plenty of options.

$AdGroupMemberList = Get-ADGroupMember -Identity 'GenericGroup'

This way you still have all properties in the array $AdGroupMemberList and you can use either a single one of them or all of them just like you need it.

And of course you still can access individual elements


But you can still use Select-Object to achieve the same result:

$AdGroupMemberList | Select-Object -ExpandProperty sAMAccountName