[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 421
  • Last Modified:

Add a user to the managed by for all computers in the file.

Hi,

I have a txt file which has the computer names and usernames.
I want to add the users to the managed by tab for the computers.

Ex:
Computername : Username

Regards
Sharath
0
bsharath
Asked:
bsharath
  • 5
  • 4
1 Solution
 
Farhan KaziSystems EngineerCommented:
Posting script in few minutes :)
0
 
Farhan KaziSystems EngineerCommented:
:: ===============
:: READ THIS FIRST
:: ===============
:: * This script require 'Computers.txt' file from where it will pick computer names and usernames.
:: * 'Computers.txt' file should be in following format
::               ComputerName:UserSAMAccountName
::      Like:
::                PC733:FKazi
:: * 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 "tokens=1-2 delims=:" %%a IN ('TYPE Computers.txt') Do (
    ECHO Processing: %%a
    SET ComputerDN=
      SET UserDN=
      DSQuery Computer -Name "%%a" |FIND /I "CN=">NUL
    IF NOT ERRORLEVEL 1 (
            DSQuery User -samID "%%b" |FIND /I "CN=">NUL
            IF NOT ERRORLEVEL 1 (
                  FOR /F "delims=*" %%d IN ('DSQuery Computer -Name "%%a"') DO (SET ComputerDN=%%~d)
                  FOR /F "delims=*" %%d IN ('DSQuery User -samID "%%b"') DO (SET UserDN=%%~d)
                  (      ECHO DN: !ComputerDN!
                        ECHO changetype: modify
                        ECHO replace: managedBy
                        ECHO managedBy: !UserDN!
                        ECHO -
                        ECHO.)>>CompMgr.ldf
            ) ELSE (ECHO *** ERROR *** %%b: User NOT Found in AD.)
      ) ELSE (ECHO *** ERROR *** %%a: Computer 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:
Farhan when we add the users to the manaed by tab.Is it just for information purpose or will the user be given some kind of permissions?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
bsharathAuthor Commented:
Farhan when we add the users to the manaed by tab.Is it just for information purpose or will the user be given some kind of permissions?
0
 
Farhan KaziSystems EngineerCommented:
Thats just for information (so that this person will be contacted in-case any problem or concern related that machine raises).
0
 
bsharathAuthor Commented:
Thanks...
0
 
Farhan KaziSystems EngineerCommented:
Ohoh! I think Im wrong :(

Check following link:
http://www.microsoft.com/technet/prodtechnol/windowsserver2003/technologies/directory/activedirectory/stepbystep/admng.mspx
It says...

Creating a Computer Object

A computer object is created automatically when a computer joins a domain. If you do not want to give all users the ability to add computers to the domain, computer objects may also be created before the computer joins a domain manually or via scripts.

To manually add a computer to the domain

1.Right-click the Engineering OU, point to New, and then click Computer.
2.For the computer name, type Legacy, and then click Next.
3.If the computer is a managed system, you can enter the system GUID. In this example, leave the system GUID blank, click Next, and then click Finish.
4.To manage this computer from the Active Directory Users and Computers snap-in, right-click the computer object, and then click Manage.

That means that user can join that specific machine to Domain (if already created manually in AD and assigned that user in Managed By)
0
 
bsharathAuthor Commented:
Ok...

If the machines are being joined to Domain and i add the user to the managed by that means that user with his credentials can access the machine to the Domain...?
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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