I want to write this command-line (one-liner) to get members of an ad-Group and place them i a textfile. I have so far written the following:
Get-ADGroupMember xyzGroup | select samaccountname | out-file c:\temp\group.txt
But how do i trim the samaccountname. In the final text file there are spaces after each name on each line.
I can easily do this in a script:
$Members = Get-ADGroupMember xyzGroup
Foreach ($obj in $Members)
$navn = $obj.samaccountname.Trim()
$navn | out-file “c:\temp\xyzGroup_members.txt” -Append
But how do i do the same thing in the one-liner?