piping net user command problem

November 15, 2011 at 07:57:01
Specs: Windows XP
I'm trying to know if a user is part of a specific group with this simple command inside a batch:

net user /domain %username% ^| find /i "Admin"

I'm using as usual the special character "^" before the pipe knowing that it's necessary to pipe commands in a batch and ususally it works, but in this case it seems that the "find" part is parsed as a parameter of the "net" command and it fails telling me that the syntax of the command is incorrect. I know that somewhere I'm doing a really stupid error but I can't see it :)
Any suggestions?


See More: piping net user command problem

Report •

November 15, 2011 at 08:30:32
The /domain switch is listed in the documentation as following %username% rather than preceeding it. Have you tried that?

Report •

November 15, 2011 at 09:00:24
You need to escape the pipe , i.e. ^|, if part of a For /F statement NOT in a standard line; type just | however the pipe | is interpreted as a normal char not a special symbol.

Report •

November 16, 2011 at 01:14:10
Ivo it's not working, if I call the command from a shell it returns correctly with errorlevel 0 but if I try inside the script it returns errorlevel 1, which is incorrect.
Since the script relies on the right output of the errorlevel variable I'm not able to make it work properly. Even enclosing it in a "cmd /K" or "/C" enviroment didn't do the trick.

Report •

Related Solutions

November 23, 2011 at 00:54:18
sorry to bother... anyone has some advice for me?

Report •

Ask Question