locked
Get-ADGroupMember Output Formatting RRS feed

  • Question

  • I'm running the below command and I need the output to be the usernames only. I can't seem to find a way to remove the beginning (1 blank line) and ending blank (2 blank lines) returns as well as the trailing spaces behind the usernames:

    Get-ADGroupMember -identity "Domain Admins" | Select SAMAccountName | ft -hidetableheaders

    I need to pass the usernames in an Orchestrator workflow, but I can't have any empty lines or extra spaces or my workflow will fail.

    Any help is much appreciated.

    Friday, March 28, 2014 5:35 PM

Answers

  • I had to add -Identity, but that worked. Thank you very much!

    Here's the complete command for anyone else that needs it:

    get-adgroupmember -identity "Domain Admins" | select-object -expandproperty SamAccountName | out-file C:\domain_admins.txt

    I'm not sure why, but (Get-ADGroupMember -identity "Domain Admins").SamAccountName did not return anything at all. 

    • Marked as answer by jclarkemmis Friday, March 28, 2014 7:35 PM
    Friday, March 28, 2014 7:35 PM

All replies

  • (Get-ADGroupMember -identity "Domain Admins").SamAccountName


    ¯\_(ツ)_/¯

    • Proposed as answer by Mike Laughlin Friday, March 28, 2014 6:00 PM
    Friday, March 28, 2014 5:41 PM
  • Alternatively:


    get-adgroupmember "Domain Admins" | select-object -expandproperty SamAccountName


    -- Bill Stewart [Bill_Stewart]

    • Proposed as answer by Mike Laughlin Friday, March 28, 2014 7:17 PM
    Friday, March 28, 2014 6:19 PM
  • I had to add -Identity, but that worked. Thank you very much!

    Here's the complete command for anyone else that needs it:

    get-adgroupmember -identity "Domain Admins" | select-object -expandproperty SamAccountName | out-file C:\domain_admins.txt

    I'm not sure why, but (Get-ADGroupMember -identity "Domain Admins").SamAccountName did not return anything at all. 

    • Marked as answer by jclarkemmis Friday, March 28, 2014 7:35 PM
    Friday, March 28, 2014 7:35 PM
  • I'm not sure why, but (Get-ADGroupMember -identity "Domain Admins").SamAccountName did not return anything at all.

    You must be running an older version of PowerShell. This should work in V3+

    Also, just FYI - you're generally supposed to mark the posts that helped you as answers, not your own reply to them.


    Don't retire TechNet! - (Don't give up yet - 12,700+ strong and growing)

    Friday, March 28, 2014 7:40 PM