Datamation Logo

Move Computer Object to a Specified OU

November 18, 2004
Datamation content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Author: Eugenio Talarico
Platform: Windows

Type: VB Script

Description:

A BAT file that moves a computer from CN=COMPUTERS to ANOTHER that you have to specify in the VBS file.

You have to specify the list of the computers you want to move in INPUT.TXT:

''***************************************************************************** 
''* INTO STRVARIABL LINE PUT THE PATH WHERE THE object will be moved 
''* (EX: strVariabl = ",OU=Standard Users,OU=DomainNAME,")
''*****************************************************************************
''*****************************************************************************
strVariabl = "OU=Public Desktops,OU=PIPPO,OU=PIPPO"
''*****************************************************************************
''*****************************************************************************
''*****************************************************************************

Download Location:

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=56728&lngWId=1

Scroll down to view the script.


This is the batch file:

@echo off

echo ****************************************
Echo * script per move account computer *
echo ****************************************


for /F %%1 in (input.txt) do (
cscript move_cmp.vbs %%1 //B //Nologo >> err_log.txt 2>>&1 )
By
Eugenio
Script Code: dim nomepc
ParseCommandLine()


Const ADS_PROPERTY_APPEND = 3 
Set objRootDSE = GetObject("LDAP://rootDSE")


''*****************************************************************************
''* INTO STRVARIABL LINE PUT THE PATH WHERE THE object will be moved 
''* (EX: strVariabl = ",OU=Standard Users,OU=DomainNAME,")
''*****************************************************************************
''*****************************************************************************
strVariabl = "OU=Public Desktops,OU=PIPPO,OU=PIPPO"
''*****************************************************************************
''*****************************************************************************
''*****************************************************************************
strFissa =  strVariabl & "," & objRootDSE.Get("defaultNamingContext")
wscript.echo strFissa



Set objNewOU = GetObject("LDAP://"& strFissa)
Set objMoveComputer = objNewOU.MoveHere _
("LDAP://CN="& nomepc & ",CN=Computers," & objRootDSE.Get("defaultNamingContext"), "CN=" &nomepc)


Sub ParseCommandLine()
  	Dim vArgs

  	set vArgs = WScript.Arguments
  
  	if vArgs.Count  1 then 
  		DisplayUsage()
  	Else
 		nomepc = vArgs(0)
	End if
End Sub


Disclaimer: We hope that the information in these pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided “as – is”, without any warranty, whether express or implied, of its accuracy,
completeness, fitness for a particular purpose, title or non-infringement, and none of the third-party products or information mentioned in the work are authored, recommended, supported or guaranteed by me. I shall not be liable for any damages you
may sustain by using this information, whether direct, indirect, special, incidental or consequential, even if it has been advised of the possibility of such damages.

  SEE ALL
APPLICATIONS ARTICLES
 

Subscribe to Data Insider

Learn the latest news and best practices about data science, big data analytics, artificial intelligence, data security, and more.

Datamation Logo

Datamation is the leading industry resource for B2B data professionals and technology buyers. Datamation's focus is on providing insight into the latest trends and innovation in AI, data security, big data, and more, along with in-depth product recommendations and comparisons. More than 1.7M users gain insight and guidance from Datamation every year.

Advertisers

Advertise with TechnologyAdvice on Datamation and our other data and technology-focused platforms.

Advertise with Us

Our Brands


Privacy Policy Terms & Conditions About Contact Advertise California - Do Not Sell My Information

Property of TechnologyAdvice.
© 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.