Get output of a CMD command and set it to a batch variable
The output of WMIC is unicode !
The trailing <CR>
can be removed by passing the value through another FOR /F loop. This also removes the phantom "blank" line (actually a <CR>
)
@echo off
set "remotegroup="
for /f "skip=1 delims=" %%a in ('"wmic group where sid="S-1-5-32-555" get name"') do (
for /f "delims=" %%b in ("%%a") do if not defined remotegroup set "remotegroup=%%~nb"
)
echo "%remotegroup%"
pause