1

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?

kylex
  • 1,463

1 Answers1

4

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
jscott
  • 25,114