I'm trying to end up with a txt file of usernames (1 user per line) using the

net group /domain <group>

command. However, the output of this command is not conducive to parsing. Does anyone have a way to pipe this to a txt file so that the file consists of only one user per line?

  • 4
    No Powershell? Get-ADGroupMember "groupname" | Select name | Export-Csv -NoTypeInformation output.csv – jscott Jul 30 '14 at 16:54
  • @jscott, when I run that command in PS, I get: "The term Get-ADGroupMember is not recognized as the name of a cmdlet...". Also I'd prefer to use a command that doesn't require additional installations if at all possible. – kylex Jul 30 '14 at 16:55
  • 1
    You need Microsoft's Active Directory Powershell module. It's included in RSAT and Server 2008/2012. – jscott Jul 30 '14 at 16:57
  • Might use dsget group instead of net /group. Powershell with the AD modules is the right way though. – Zoredache Jul 30 '14 at 18:03

Ok, no additional installs, I get it. The following is horrible, horrible, and I would suggest there must be a better way [use the AD module!] to do it. I didn't feel like writing this in batch just now, so here it is. Note there isn't even a hint of i18n, error handling or anything "sane" here.

# Powershell
$result = net group /domain "SomeGroup"
($result |
    Where-Object { $_ -notmatch '^(The request|$|Group Name|Comment|Members|--|The c)' }).Split(' ') |
        Where-Object { $_ } |
             Out-File group.txt
| improve this answer | |
  • 2
    Thanks, and I think you're right... It'll be better to install the module. – kylex Jul 30 '14 at 17:20
  • You'll be so much happier with the AD module, I promise. :) – jscott Jul 30 '14 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.