How to output net group command in list format in batch
8,501
Please attempt something before asking next time.
Assuming the output of the command is roughly:
bossMan Arescet Ice
superuser lazyWorker Dog
(etc...)
As i am unsure of the output of this file from where I'm writing this, I don't know if a prefix to the output is given that needs to be ignored.
:: First attempt with a single line;
for /f %%G in ('net group "Groupname" /domain') do (echo %%G)
Now i prefer using files by habit of backups and odd character handling so i would use this, although it is 3 lines and writes to a file;
:: Write the output of your command into a file:
net group "Groupname" /domain >userList.temp
:: Split the content by spaces, and write each space separated token.
:: Column 1 is %%~G, 2 is %%~H, 3 is %%~I.
for /f %%G in (userList.tmp) do (
echo %%~G
echo %%~H
echo %%~I
)
:: Cleanup the temp file;
del "userList.temp"
Of course >>output.ext
can be applied individually to %%~G %%~H %%~I
, or a call with that specified column of the current line.
Related videos on Youtube
Author by
Ice
Updated on September 18, 2022Comments
-
Ice over 1 year
I'm using the
net group "Groupname" /domain
command which outputs a bunch of users in the group in the format of 3 columns. There are spaces between the columns.How do I output the command so that there is one user per line?
-
Ice about 8 yearsDoing this only outputs the first column, not the second and third.
-
Bloodied about 8 yearsFixed, don't know how i missed that.