In Power Shell I try to get all members of an AD group with the following command:
$users=Get-ADGroupMember -Identity 'AD-Group-XYZ' -Recursive | Select SamAccountName
Then if I try to print the first username by typing:
$users[0]
I get the following output:
SamAccountName
--------------
usenameX
The question is how can I get only the output:
usenameX
and skip:
SamAccountName
--------------
I tried the following but nothing works:
$users[0].ToString()
$users[0].text
$users[0].text.ToString()
The reason is that I want to iterate in all usernames and create a string where I concatenate them and split them with a space.