Batch script to move users to different OUs

Giganews Newsgroups
Subject: Batch script to move users to different OUs
Posted by:  Serrix (Serrix.3ksk…
Date: Mon, 22 Dec 2008

Hi there,
We're almost ready to re-direct the default computers location and to
set up a GPO startup script to move the machines from the default
location to a OU based on their hardware type. This move is based on a
file which is created when the machine is imaged.

Here is the batch script, please let me know if you see any
I've replaced all site specifics with placeholders in []s

@echo off
setlocal enabledelayedexpansion
set currentline=
set LogFile=%Temp%\%~n0.log

set MoveUser=[Domain user with priviledges to move computers]
set MovePwd=[Above user's password[
set Root=dc=[something],dc=[somewhere],dc=[somewhere]
set ComputersDN=ou=Workstations,%root%
set Desktop=ou=Desktops,ou=Workstations,%root%
set Laptop=ou=ou=Laptops,Workstations,%root%
set TargetDN=

if not exist C:\WINDOWS\[FOLDER]\SysInfo\CHASSIS.TXT goto end
for /f %%a in (C:\WINDOWS\[FOLDER]\SysInfo\CHASSIS.TXT) do (
    set currentline=%%a
if /i %currentline% == LAPTOP set TargetDN=%Laptop%
if /i %currentline% == DESKTOP set TargetDN=%Desktop%

echo %Date% %Time% About to move "%ComputerName%" to "%TargetDN%":
>>"%LogFile%" echo %Date% %Time% About to move "%ComputerName%" to

dsquery computer "%ComputersDN%" -name %ComputerName% | dsmove computer
-newparent "%TargetDN%" -u %MoveUser% -p %MovePwd% >>"%LogFile%" 2>&1


Thanks in advance

Serrix's Profile:
View this thread: