Provost
asked on
Put the result of findstr in a variable in a batch file on Windows
Could you tell me how to put the result of this command in a variable in a batch script?
If i type this line: echo "This is a test" | findstr "is"
I got this: "This is a test"
I want this result i a variable
If i type this line: echo "This is a test" | findstr "is"
I got this: "This is a test"
I want this result i a variable
ASKER
If i try this in a command line (this is the real thing)
for /F "delims=" %T in ('net localgroup "Utilisateurs du Bureau à distance" | findstr "ADMINISTRATIF\SAV$cont-ex ec"') do set var=%T
I got
| was expected.
for /F "delims=" %T in ('net localgroup "Utilisateurs du Bureau à distance" | findstr "ADMINISTRATIF\SAV$cont-ex
I got
| was expected.
ASKER
This comman alone return what i'm looking for.
The goal is to check if a user is member of a localgroup.
net localgroup "Utilisateurs du Bureau à distance" | findstr "ADMINISTRATIF\SAV$cont-ex ec"
return this:
ADMINISTRATIF\SAV$cont-exe c
The goal is to check if a user is member of a localgroup.
net localgroup "Utilisateurs du Bureau à distance" | findstr "ADMINISTRATIF\SAV$cont-ex
return this:
ADMINISTRATIF\SAV$cont-exe
The caret ^ as shown in my code is required to "escape" the pipe character
ASKER
for /F "delims=" %T in ('net localgroup "Utilisateurs du Bureau à distance" ^| findstr "Utilisateurs du Bureau à distance"') do set var=%T
echo %var%
return this instead of ADMINISTRATIF\SAV$cont-exe c
Commentaire Les membres de ce groupe disposent des droits nécessaires pour ouvrir une session à distance
echo %var%
return this instead of ADMINISTRATIF\SAV$cont-exe
Commentaire Les membres de ce groupe disposent des droits nécessaires pour ouvrir une session à distance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
but that is probably too simplified for being used for an actual purpose ...