Page 1 of 1

Localgroup Administrators

Posted: 10 Mar 2016 06:19
by kethies83
I have script that will collect members of local server administrator group. But however i need some help on the output method. can someone assist me please

script

Code: Select all

@ECHO OFF
SETLOCAL
SET "admins="
SET "prev="
FOR /f "delims=" %%A IN ('net localgroup administrators') DO (
 CALL SET "admins=%%admins%% %%prev%%"
 SET "prev=%%A"
)
SET admins=%admins:*- =%
ECHO admins are %admins%
GOTO :EOF



output
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
admins are ASIAPACIFIC\Domain Admins ASIAPACIFIC\user2 hpadmin hpdisabled user1
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

desire output
admins are;
ASIAPACIFIC\Domain Admins
ASIAPACIFIC\user2
hpadmin
hpdisabled
user1

Re: Localgroup Administrators

Posted: 10 Mar 2016 11:51
by foxidrive
If you paste the screen output from net localgroup administrators into a reply then it may be clearer.

Re: Localgroup Administrators

Posted: 10 Mar 2016 17:06
by Squashman

Code: Select all

ECHO admins are:
for /F "skip=4 delims=" %%G in ('net localgroup administrators') do echo %%G |find /V "The command completed"

Re: Localgroup Administrators

Posted: 11 Mar 2016 06:06
by b0gus
kethies83 wrote:I have script that will collect members of local server administrator group.
But however i need some help on the output method.
can someone assist me please
.....
I do approximately so:

Code: Select all

@echo off
setlocal
echo:...wait
for %%v in (wmic.exe) do if "%%~$path:v"=="" (echo:OS missing wmic.exe&pause&exit /b 1)
set "Name="
for /f %%v in ('2^>nul wmic.exe path Win32_Group where SID^="S-1-5-32-544" get name /Format:value^|more +2') do for /f "delims=" %%n in ("%%v") do (set %%n)
if NOT defined Name echo:OS missing group with SID=S-1-5-32-544&pause&exit /b 2
set "admins=" & set "x="
for /f "tokens=*" %%v in ('net localgroup %Name%') do call set "admins=%%admins%% "%%x%%"" & set "x=%%v"
cls
echo:users from localgroup "%Name%":
for %%v in (%admins:*-" =%) do echo:    %%~v
pause
exit /b 0

Re: Localgroup Administrators

Posted: 18 Mar 2016 01:56
by kethies83
Hi Squashman,

thanks for the great help.. just 1 small favor. the output has the "-------". can it be removed.
thanks in advance

admins are
-------------------------------------------------------------------------------
ASIAPACIFIC\Domain Admins
ASIAPACIFIC\user1
hpadmin
hpdisabled
user2

Re: Localgroup Administrators

Posted: 20 Mar 2016 11:44
by foxidrive
skip=4 removes the top 4 lines from the net localgroup administrators command output.

It may work if you change 4 to 5.

Here in Windows 8.1 you have to use 6 because the number of lines before the first admin name is 6.