Different ways to get the same results By ThunderJun:
OP1: Here we use setlocal to activate the use of special variables of the
delayed type (!var!) Without using a for within another for. To get the same
result.
OP2: Here we assign the command in a common type variable and with the help of
vertical bar, we combine several commands, always taking priority
first. We add the filter: more +1 to indicate to ignore the first
output line and then add the filter: findstr /i "remot" with another
vertical bar, with this we are indicating, that only print lines that
contain the keyword that is in quotes and that does not distinguish
between upper or lower case letters. Then we use a type variable
common indicating to it, not to show the last 3 characters: %var:~0,-3%
In this way, we get the same result without using a for within another for.
OP3: Here we use setlocal, to activate the use of special variables of
delayed type (!var!). With a vertical bar, at the end of the command inside the for. For it, we assign a filter with the command: findstr /i "remot"
indicating that it only prints lines with the keyword in quotes and that does not distinguish between upper and lower case letters. We use a special variable of delayed type, to capture the command output and we indicate replace 2 characters of spaces for nothing (!var: =!), to achieve the same result without using a for inside from another to.
@echo off
:::::::::::::OP1 START. BY ThunderJun
setlocal enabledelayedexpansion
set remotegroup=
for /f "skip=1 delims=" %%a in ('"wmic group where sid="S-1-5-32-555" get name"') do (
set remotegroup=%%a!remotegroup:~0,-4!
set rio=!remotegroup:~0,-1!
set remotegroup=!rio:~0,-1!
)
echo OP1 "%remotegroup%"
:::::::::::::OP1 END
:::::::::::::OP2 START. BY ThunderJun
set a='"wmic group where sid="S-1-5-32-555" get name |more +1 |findstr /i "remot""'
for /f "delims=" %%c in (%a%) do (set remotegroup=%%c)
echo OP2 "%remotegroup:~0,-3%"
:::::::::::::OP2 END
:::::::::::::OP3 START. BY ThunderJun
setlocal enabledelayedexpansion
set remotegroup=
for /f "delims=" %%a in ('"wmic group where sid="S-1-5-32-555" get name |findstr "remot""') do (
set remotegroup=%%~na& set remotegroup=!remotegroup: =!)
echo OP3 "%remotegroup%"
:::::::::::::OP4 END
pause