Package: ignore the last line of output

I have a pretty simple script that allows you to delete local administrator accounts. My goal is to get rid of all the header / footer information.

So far, I:

FOR /F "skip=6" %%G IN ('net localgroup administrators') DO echo %%G 

What an echo:

 Administrator MyName The 

"The first word in the footer is:" Command completed successfully. "

So I would like to get rid of "The", but I understand that I may have to rebuild the whole script, which is good. I tried to save the variable% str%, but you cannot set multiline variables. In addition, using a txt file as a buffer is not an option.

Any input?

+4
source share
1 answer

I can present two simple solutions:

 FOR /F "skip=6" %%G IN ('net localgroup administrators') DO if %%G neq The echo %%G 

or

 FOR /F "skip=6" %%G IN ('net localgroup administrators ^| findstr /vb The') DO echo %%G 

I suppose it can be argued that the username can be "The", in which case you can be more specific with a filter:

 FOR /F "skip=6" %%G IN ('net localgroup administrators ^| findstr /vc:"The command completed successfully."') DO echo %%G 
+6
source

All Articles