Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
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
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

1 Answer 1

up vote 3 down vote accepted

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
share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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