Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
kethies83
- Posts: 2
- Joined: 10 Mar 2016 06:06
#1
Post
by kethies83 » 10 Mar 2016 06:19
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
scriptCode: 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 outputadmins are;
ASIAPACIFIC\Domain Admins
ASIAPACIFIC\user2
hpadmin
hpdisabled
user1
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#2
Post
by foxidrive » 10 Mar 2016 11:51
If you paste the screen output from net localgroup administrators into a reply then it may be clearer.
-
Squashman
- Expert
- Posts: 4486
- Joined: 23 Dec 2011 13:59
#3
Post
by Squashman » 10 Mar 2016 17:06
Code: Select all
ECHO admins are:
for /F "skip=4 delims=" %%G in ('net localgroup administrators') do echo %%G |find /V "The command completed"
-
b0gus
- Posts: 7
- Joined: 02 Mar 2016 12:58
#4
Post
by b0gus » 11 Mar 2016 06:06
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
-
kethies83
- Posts: 2
- Joined: 10 Mar 2016 06:06
#5
Post
by kethies83 » 18 Mar 2016 01:56
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
-
foxidrive
- Expert
- Posts: 6031
- Joined: 10 Feb 2012 02:20
#6
Post
by foxidrive » 20 Mar 2016 11:44
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.