title image


Smiley Re: lokales Adminpasswort für alle PCs ändern
Hi!



Hatte da mal ne Lösung im Inet mit Hilfe des RemoteCmd-Service gefunden. Ansonsten einfach alle Clients z.B. mit netdom -member rausfinden und mit einem Tool wie cusrmgr in einer Schleife alle Admins zu ändern. Das Skript ist aber nobler, da es nach SIDs geht und so unabhängig vom Administrator-Namen den Admin rausfindet und ggfs. noch umbenennt:



A better method for changing the local Administrator password on all your workstations, without traveling.

In tip 0199, I scripted a tool to perform the subject function.

Using tools from the Windows NT 4.0 Resource Kit Supplement 4 or Windows 2000 Server Resource kit,

David A. Stewart, MCSE - davidastewart@email.com provides us with the following:



OS: Win NT 4.0 SP2 and up, including Windows 2000



This Password Changer routine is designed for System Admins on large domain

structures to remotely connect to every workstation on a given domain(derived

from the pdc automatically), find the built-in local administrator account(no

matter what name it may be), check for accounts with duplicate names as the

intended name change, delete the duplicate accounts, rename it to some standard

convention, and then change the password of that account.



It is written to sort out servers and not change them. The user running the

script must have admin rights on the subject systems. At completion of the

batch job several log files are generated denoting the status of the systems.

Additionally, a working file is left in the directory containing systems that

were not online at the time of the batch job being run. This file will be

detected if the batch job is run again and batch job will try to connect to

the remaining systems listed in the file. The name of the file is working.txt.



There are three variables set at the beginning of the script that must be edited,

to match your environment, in the MASTER.BAT file. They are as follows:



set CurrentDomain=mydomain

set localadmin=localadmin

set password=password



The batch job will not run unless these variable strings are modified from the

default settings.



The author of this script offerings it to help other admins save hundreds of

hours of footwork.



David A. Stewart, MCSE

Sr. Systems Administrator/RL-ATD/Eastman Kodak Co.

Email: davidastewart@email.com



@echo off

setlocal



REM Authored by David A. Stewart x20516 RL/ATD B83 Flr8 d-stewart@bigfoot.com

REM Discovers Built-in administrator account on workstations.

REM Deletes any account with the same name as the new account name.

REM Renames the Built-in administrator account to the new name.

REM Changes the password to the new password.



set CurrentDomain=mydomain

set localadmin=localadmin

set password=password



:start

cls

if (%CurrentDomain%) == (mydomain) echo Edit the first "set=" line of MASTER.BAT

if (%CurrentDomain%) == (mydomain) echo then rerun MASTER.BAT

if (%CurrentDomain%) == (mydomain) goto finished

if (%localadmin%) == (localadmin) echo Edit the second "set=" line of MASTER.BAT

if (%localadmin%) == (localadmin) echo then rerun MASTER.BAT

if (%localadmin%) == (localadmin) goto finished

if (%password%) == (password) echo Edit the third "set=" line of MASTER.BAT

if (%password%) == (password) echo then rerun MASTER.BAT

if (%password%) == (password) goto finished

echo.

echo ************************************************************************

echo ************************************************************************

echo *************** ***************

echo *************** Local Admin Discovery N Password Changer ***************

echo *************** ***************

echo ************************************************************************

echo ************************************************************************

rem *** Display current variable settings ***

echo.

echo Current Domain is %CurrentDomain%.

echo Current Local Admin is %localadmin%.

echo Current Password is %password%.

echo.

pushd .\files

rem *** Determine if working list is present ***

If exist working.txt echo Working list detected, resuming batch process.

If exist working.txt goto SkipCreateList

echo Creating a list of member servers in %CurrentDomain%.

echo.

netdom /d:%CurrentDomain% member > working.txt

rem *** Remove NETDOM formatting from server names ***

if exist temp.txt del temp.txt

for /F "skip=6 delims=\\ tokens=2" %%a in (working.txt) do call :sub1 %%a

del working.txt

ren temp.txt working.txt

:SkipCreateList

rem *** Determine if machine is online ***

for /F "delims=\\ tokens=1" %%a in (working.txt) do call :sub2 %%a

REM *** Remove servers that have been processed from WORKING.TXT ***

if not exist online.txt goto NoServersOnline

echo.

echo Updating list of servers that need to be processed.

for /F %%a in (complete.txt) do call :sub4 %%a

for /F %%a in (undetermined.txt) do call :sub4 %%a

for /F %%a in (dc.txt) do call :sub4 %%a

for /F %%a in (svr.txt) do call :sub4 %%a

for /F %%a in (errored.txt) do call :sub4 %%a

echo.

echo List complete.

goto Bottom

:NoServersOnline

Echo.

Echo There are no servers currently online that can be processed.

:Bottom

echo.

echo ------------------------------------

echo --- Finished processing servers. ---

echo ------------------------------------

echo.

:RESULTS

IF EXIST RESULTS DEL .\RESULTS\*.* /Q /S

IF EXIST RESULTS RD RESULTS

MD RESULTS

IF EXIST ONLINE.TXT DEL ONLINE.TXT

IF EXIST OFFLINE.TXT MOVE OFFLINE.TXT .\RESULTS\OFFLINE.TXT

IF EXIST SVR.TXT MOVE SVR.TXT .\RESULTS\SVR.TXT

IF EXIST undetermined.txt MOVE undetermined.txt .\RESULTS\undetermined.txt

IF EXIST dc.txt MOVE dc.txt .\RESULTS\dc.txt

IF EXIST complete.txt MOVE complete.txt .\RESULTS\complete.txt

IF EXIST errored.txt MOVE errored.txt .\RESULTS\errored.txt

IF EXIST WORKING.TXT COPY WORKING.TXT .\RESULTS\WORKING.TXT

IF EXIST Oldadmin.log COPY Oldadmin.log .\RESULTS\Oldadmin.log

echo.

echo.

goto finished



REM SUB-ROUTINES

:sub1

rem *** Remove formatting from Netdom output ***

echo %1 >> temp.txt

goto :EOF

:sub2

echo Pinging %1...

echo.

ping %1 > PING.TXT

for /F "skip=6 tokens=4" %%a in (PING.TXT) do call :sub3 %%a %1

del PING.TXT

goto :EOF

:sub3

rem *** %2 is a bogus variable, thrown away.

if not (%1) == (bytes) goto NotOnline

set computer=%3

echo [%computer% is online.]

echo %computer% >> online.txt

rem ***********************************************

rem *** The following section determines if *******

rem *** Workstation or Server is running *******

rem ***********************************************

set product_type=

reg query hklm\system\currentcontrolset\control\ProductOptions\ProductType \\%computer% > msid.txt

for /F "skip=1 delims= tokens=3" %%i IN (msid.txt) DO set product_type=%%i

If exist msid.txt del msid.txt

if "%product_type%"=="WinNT" goto Workstation

if "%product_type%"=="ServerNT" goto Server

if "%product_type%"=="LanmanNT" goto DomainController

:Undetermined

echo.

echo Unable to determine Windows NT Product Type, check the following

echo registry key for product type

echo hklm\system\currentcontrolset\control\ProductOptions\ProductType

echo.

echo Expected values

echo.

echo ProductType Product

echo ----------------------------------------------------

echo WinNT Windows NT Workstation is running

echo ServerNT Windows NT Server is running

echo LanmanNT Windows NT Domain controller

echo.

echo %computer% >> undetermined.txt

goto Sub3end

:DomainController

echo.

echo The product type is %product_type%.

echo %computer% >> dc.txt

echo %3 is a Domain Controller and the local admin password is not changed.

goto Sub3end

:Server

echo.

echo The product type is %product_type%.

echo %computer% >> svr.txt

echo %computer% is a Server and the local admin password is not changed.

goto Sub3end

:Workstation

echo.

echo The product type is %product_type%.

REM ***********************************************

REM *** Put per-server processing commands here ***

REM ***********************************************

echo.

echo **** Working on workstation %computer% now. ****

echo.

REM Install and load Remote Command Server service

SET error=

call :loadsvc %computer%

ECHO.

REM Check for Remote Command Server load failure

If (%error%)==(error) goto failure1

REM Return Local Admin Name to %%currentadmin%%

call :getadmins

ECHO.

REM Check for Local Admin Name find failure

If (%currentadmin%)==() goto failure2

REM Change %%currentadmin%% name to %%localadmin%% name.

call :chgname

ECHO.

REM Check for Local Admin Name change failure

If (%change_name_error%)==(error) goto failure3

REM Change the Password

Rcmd \\%computer% net user %localadmin% %password%

REM Unload Remote Command Server service

call :unldsvc %computer%

REM *****************************************************

REM *** Put per-server processing commands above here ***

REM *****************************************************

ECHO %computer% >> complete.txt

goto Sub3end

:failure1

echo.

echo Remote Command Server service could not install and start on \\%computer%.

echo.

echo %computer% RCMD_server_error >> errored.txt

REM Unload Remote Command Server service

call :unldsvc %computer%

goto Sub3end

:failure2

echo.

echo Could not find the Local Administrator on \\%computer%.

echo.

echo %computer% Local_Admin_Not_Found >> errored.txt

REM Unload Remote Command Server service

call :unldsvc %computer%

goto Sub3end

:failure3

echo.

echo Local Administrator Name on \\%computer% was not changed correctly.

echo.

echo %computer% Local_Admin_Name_Not_Changed >> errored.txt

REM Unload Remote Command Server service

call :unldsvc %computer%

goto Sub3end

:NotOnline

echo %computer% is offline.

echo %computer% >> offline.txt

:Sub3end

echo ********************************************************************************

echo ******************** Workstation %computer% Processed **********************

echo ********************************************************************************

goto :EOF

:sub4

rem *** loop thru each name in working.txt and remove machines that were***

rem *** online***

echo Removing %1 from list.

if exist temp.txt del temp.txt

for /F "tokens=1" %%a in (working.txt) do call :sub5 %%a %%1

del working.txt

if exist temp.txt ren temp.txt working.txt

goto :EOF

:sub5

rem *** Filter out servers that have been updated ***

rem %1 is name from working.txt

rem %2 is name from %file%

if not (%1) == (%2) echo %1 >> temp.txt

goto :EOF

:Checkadmin

set sid=

set currentadmin=

set tempcomputer=

IF EXIST checkadmin.txt DEL checkadmin.txt

local.exe administrators \\%computer% > checkadmin.txt

FOR /F "delims=\ tokens=1,2*" %%i IN (checkadmin.txt) DO call :checkadmin2 %%i %%j

echo.

echo Current Local Admin is now %currentadmin%

echo Current Local Admin SID is %sid%

echo.

IF EXIST checkadmin.txt DEL checkadmin.txt

goto :EOF

:checkadmin2

set tempcomputer=

set tempname=

set tempcomputer=%1

set tempname=%2

IF NOT {%currentadmin%} == {} goto :EOF

IF {%2} == {} goto :EOF

IF {%2} == { } goto :EOF

IF /I NOT (%tempcomputer%)==(%computer%) goto :EOF

IF /I (%tempname2%) == (%localadmin%) SET ekadmin=TRUE

IF EXIST checkadmin2.txt DEL checkadmin2.txt

user2sid.exe \\%tempcomputer% %tempname% > checkadmin2.txt

FOR /F "delims=- tokens=1-8" %%i IN (checkadmin2.txt) DO call :checkadmin3 %%i %%j %%k %%l %%m %%n %%o %%p

IF EXIST checkadmin2.txt DEL checkadmin2.txt

goto :EOF

:checkadmin3

set rid=500

IF %1 == LookupAccountName goto :EOF

IF {%8} == {} goto :EOF

IF {%8} == { } goto :EOF

IF NOT {%8} == {%rid%} goto :EOF

set sid=%1-%2-%3-%4-%5-%6-%7-%8

set currentadmin=%tempname%

goto :EOF

:chgname

set change_name_error=

echo.

xcopy netuser.exe \\%computer%\admin$\system32

xcopy akro8.bat \\%computer%\admin$\system32

Rcmd \\%computer% akro8.bat

call :checkadmin

IF NOT %currentadmin% == %localadmin% set change_name_error=error

del \\%computer%\admin$\system32\netuser.exe

del \\%computer%\admin$\system32\akro8.bat

del .\akro8.bat

goto :EOF

:deladmin

set ekadmin=false

call :getadmins4

IF /I NOT (%ekadmin%) == (TRUE) goto :EOF

Rcmd \\%computer% NET USER %tempname% /DELETE

echo.

echo Deleted Admin account %computer%\%tempname%

echo.

goto :EOF

:getadmins

set sid=

set currentadmin=

set tempcomputer=

IF EXIST getadmins.txt DEL getadmins.txt

local.exe administrators \\%computer% > getadmins.txt

FOR /F "delims=\ tokens=1,2*" %%i IN (getadmins.txt) DO call :getadmins2 %%i %%j

echo.

echo Current Local Admin is %currentadmin%

echo Current Local Admin SID is %sid%

echo.

echo netuser.exe %currentadmin% /name:%localadmin% > akro8.bat

If /I NOT {%currentadmin%} == {ekadmin} echo %computer% %currentadmin% >> Oldadmin.log

DEL getadmins.txt

goto :EOF

:getadmins2

set tempcomputer=

set tempname=

set tempcomputer=%1

set tempname=%2

REM IF NOT {%currentadmin%} == {} goto :EOF

IF {%2} == {} goto :EOF

IF {%2} == { } goto :EOF

IF /I NOT (%tempcomputer%)==(%computer%) goto :EOF

IF EXIST getadmins2.txt DEL getadmins2.txt

user2sid.exe \\%tempcomputer% %tempname% > getadmins2.txt

FOR /F "delims=- tokens=1-8" %%i IN (getadmins2.txt) DO call :getadmins3 %%i %%j %%k %%l %%m %%n %%o %%p

IF EXIST getadmins2.txt DEL getadmins2.txt

goto :EOF

:getadmins3

IF {%currentadmin%} == {%localadmin%} goto :EOF

set rid=500

IF %1 == LookupAccountName goto :EOF

IF {%8} == {} goto :EOF

IF {%8} == { } goto :EOF

IF {%8} == {%rid%} goto bottom

IF /I (%tempname%)==(%localadmin%) call :deladmin

goto :EOF

:bottom

set sid=%1-%2-%3-%4-%5-%6-%7-%8

set currentadmin=%tempname%

goto :EOF

:getadmins4

IF EXIST getadmins4.txt DEL getadmins4.txt

local.exe administrators \\%computer% > getadmins4.txt

FOR /F "delims=\ tokens=1,2*" %%i IN (getadmins4.txt) DO call :getadmins5 %%i %%j

IF EXIST getadmins4.txt DEL getadmins4.txt

goto :EOF

:getadmins5

set tempcomputer2=

set tempname2=

set tempcomputer2=%1

set tempname2=%2

IF {%2} == {} goto :EOF

IF {%2} == { } goto :EOF

IF /I %tempcomputer2% NEQ %computer% goto :EOF

IF /I (%tempname2%) == (%localadmin%) SET ekadmin=TRUE

goto :EOF

:loadsvc

REM Install, Start, and Status Test the Remote Command Server

set error=none

echo.

xcopy Oemnsvrc.inf \\%computer%\admin$\system32\

xcopy Rcmdsvc.exe \\%computer%\admin$\system32\

echo.

SC \\%computer% CREATE RemoteCmd binpath= %systemroot%\system32\Rcmdsvc.exe START= Demand TYPE= own DEPEND= LanmanServer DisplayName= "Remote Command Server"

SC \\%computer% START RemoteCmd

echo.

call :rcmdtest

GOTO :EOF

:rcmdtest

set rcmd_error=error

set state=

IF EXIST rcmdtest.txt DEL rcmdtest.txt

sc \\%computer% query RemoteCmd > rcmdtest.txt

FOR /F "skip=3 eol=0 delims=: Tokens=2" %%i IN (rcmdtest.txt) DO call :rcmdtest2 %%i

IF (%rcmd_error%)==(error) echo The RemoteCmd service is not running.

IF (%rcmd_error%)==(error) SET error=error

IF EXIST rcmdtest.txt DEL rcmdtest.txt

GOTO :EOF

:rcmdtest2

set state=%1

IF NOT {%state%}=={4} goto :EOF

echo Current state is running.

set rcmd_error=none

goto :EOF

:unldsvc

REM Stop and remove the Remote Command Server

echo.

SC \\%computer% STOP RemoteCmd

SC \\%computer% DELETE RemoteCmd

del \\%computer%\admin$\system32\Oemnsvrc.inf

del \\%computer%\admin$\system32\Rcmdsvc.exe

echo.

goto :EOF

REM BOTTOM OF SUB-ROUTINES

:finished

popd

endlocal





Gruss

MaxMad

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: