Skip navigation

JSI Tip 10561. How can I move all the NetBIOS computer names specified in a text file to a new OU (Organizational Unit)?


Using AdFind.exe freeware and ADMod.exe freeware, I have scripted MoveOUN.bat to move all the NetBIOS computer names specified in a text file to a new OU.

The syntax for using MoveOUN.bat is:

MoveOUN Filename NewOU

Where:

FileName is the file that contains the NetBIOS computer names, one per line, that you want to move to New OU.

New OU   is the new OU that you want all the objects in FileName to be moved to, like "OU=East Coast,DC=JSIINC,DC=COM"
NOTE: See How can I move all the Distinguished Names specified in a text file to a new OU (Organizational Unit)?

MoveOUN.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: MoveOUN Filename NewOU&goto :EOF
if not exist %1 @echo MoveOUN %1 does not exist.&goto :EOF
setlocal ENABLEDELAYEDEXPANSION
set file=%1
set newou=%2
for /f "Tokens=*" %%a in ('type %file%') do (
 set name=%%a
 set OK=N
 for /f "Tokens=*" %%b in ('adfind -default -nodn -csv -nocsvheader -f "&(objectcategory=computer)(name=%%a)" distinguishedName^|find "="') do (
  set OK=Y
  @echo admod -b %%b -unsafe -move %newou%
  admod -b %%b -unsafe -move %newou%
 )
 if "!OK!" EQU "N" @echo !name! was NOT found.
)
endlocal



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish