• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

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
0
bsharath
Asked:
bsharath
  • 2
1 Solution
 
Farhan KaziSystems 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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now