Clear the Managed by details on only computers in the file.

Hi,

I have a list of machine names need to clear the managed by tab details of all those computers only.
Have a results file.

Regards
Sharath
LVL 11
bsharathAsked:
Who is Participating?
 
Farhan KaziConnect With a Mentor Systems EngineerCommented:
:: ===============
:: READ THIS FIRST
:: ===============
:: * This script require "Computers.txt" file from where it will pick computer names.
:: * Copy and paste following script in notepad and save it with any name having .cmd extension.
:: *** SCRIPT START ***
@ECHO OFF
SETLOCAL EnableDelayedExpansion
IF NOT EXIST Computers.txt GOTO ShowErr
FOR %%R IN (Computers.txt) DO IF %%~zR EQU 0 GOTO ShowErr
IF EXIST CompMgr.ldf DEL /F /Q CompMgr.ldf

FOR /F %%c IN ('TYPE Computers.txt') Do (
    ECHO Processing: %%c
    DSQuery Computer -Name %%c |FIND /I "CN=">NUL
    IF NOT ERRORLEVEL 1 (
            FOR /F "delims=*" %%d IN ('DSQuery Computer -Name %%c') DO ((
                  ECHO DN: %%~d
                  ECHO changetype: modify
                  ECHO replace: managedBy
                  ECHO managedBy: %%~d
                  ECHO -
                  ECHO.
                  ECHO DN: %%~d
                  ECHO changetype: modify
                  ECHO delete: managedBy
                  ECHO -
                  ECHO.)>>CompMgr.ldf)
      ) ELSE (ECHO *** ERROR *** %%c: System NOT Found in AD.)
)
ECHO.
IF EXIST CompMgr.ldf LDIFDE -I -K -F CompMgr.ldf
GOTO EndScript
:ShowErr
ECHO "Computers.txt" file does not exist or file is empty!
:EndScript
IF EXIST CompMgr.ldf DEL /F /Q CompMgr.ldf
ENDLOCAL
:: *** SCRIPT END ***
0
 
bsharathAuthor Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.