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

Jerold Schulman

June 8, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today


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 offif {%2}=={} @echo Syntax: MoveOUN Filename NewOU&goto :EOFif not exist %1 @echo MoveOUN %1 does not exist.&goto :EOFsetlocal ENABLEDELAYEDEXPANSIONset file=%1set newou=%2for /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



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like