Jump to content

Help with script to move computers in AD


Recommended Posts

I am currently using a batch file in combination with a VB Script to move computers from the default directory where they go when being added to the domain. I would like to rewrite this in AutoIt so that it has a more user friendly interface.

Here is the VB Script I have been using. (I didn't write this. It was written by Chimera Computing Ltd)

Option Explicit 

' Declare variables 
dim objOU, objPC, objRootDSE, strDNSDomain 
dim sSourceCN, sDestCN, objNet, sThisComputer 

' Find this computer name 
set objNet = CreateObject("WScript.NetWork") 
sThisComputer = objNet.ComputerName 
 
' Get AD details 
set objRootDSE = GetObject("LDAP://RootDSE") 
strDNSDomain = objRootDSE.Get("DefaultNamingContext") 

' Set query source and destination 
sSourceCN = "LDAP://CN=" & sThisComputer & ",OU=Computers," & strDNSDomain 
sDestCN = "LDAP://OU=Division,OU=Region,OU=City,OU=Computers," & strDNSDomain 

' Move computer object 
set objOU = GetObject(sDestCN) 
WScript.echo "Moving computer account" 
set objPC = objOU.MoveHere(sSourceCN, vbNullString)
WScript.echo & sThisComputer $ " has successfully been moved to " & sDestCN & vbNewline

I am new to AutoIt and have VERY LITTLE knowledge of VB Scripting. Any help with this is appreciated.

Link to comment
Share on other sites

  • Developers

I am currently using a batch file in combination with a VB Script to move computers from the default directory where they go when being added to the domain. I would like to rewrite this in AutoIt so that it has a more user friendly interface.

Here is the VB Script I have been using. (I didn't write this. It was written by Chimera Computing Ltd)

Option Explicit 

' Declare variables 
dim objOU, objPC, objRootDSE, strDNSDomain 
dim sSourceCN, sDestCN, objNet, sThisComputer 

' Find this computer name 
set objNet = CreateObject("WScript.NetWork") 
sThisComputer = objNet.ComputerName 
 
' Get AD details 
set objRootDSE = GetObject("LDAP://RootDSE") 
strDNSDomain = objRootDSE.Get("DefaultNamingContext") 

' Set query source and destination 
sSourceCN = "LDAP://CN=" & sThisComputer & ",OU=Computers," & strDNSDomain 
sDestCN = "LDAP://OU=Division,OU=Region,OU=City,OU=Computers," & strDNSDomain 

' Move computer object 
set objOU = GetObject(sDestCN) 
WScript.echo "Moving computer account" 
set objPC = objOU.MoveHere(sSourceCN, vbNullString)
WScript.echo & sThisComputer $ " has successfully been moved to " & sDestCN & vbNewline

I am new to AutoIt and have VERY LITTLE knowledge of VB Scripting. Any help with this is appreciated.

Welcome to these forums .

There are many posts on AD stuff .. just search and see if anything is useful for you to get you started.

Moved to the correct Support forum . :)

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I am currently using a batch file in combination with a VB Script to move computers from the default directory where they go when being added to the domain. I would like to rewrite this in AutoIt so that it has a more user friendly interface.

Here is the VB Script I have been using. (I didn't write this. It was written by Chimera Computing Ltd)

Option Explicit 

' Declare variables 
dim objOU, objPC, objRootDSE, strDNSDomain 
dim sSourceCN, sDestCN, objNet, sThisComputer 

' Find this computer name 
set objNet = CreateObject("WScript.NetWork") 
sThisComputer = objNet.ComputerName 
 
' Get AD details 
set objRootDSE = GetObject("LDAP://RootDSE") 
strDNSDomain = objRootDSE.Get("DefaultNamingContext") 

' Set query source and destination 
sSourceCN = "LDAP://CN=" & sThisComputer & ",OU=Computers," & strDNSDomain 
sDestCN = "LDAP://OU=Division,OU=Region,OU=City,OU=Computers," & strDNSDomain 

' Move computer object 
set objOU = GetObject(sDestCN) 
WScript.echo "Moving computer account" 
set objPC = objOU.MoveHere(sSourceCN, vbNullString)
WScript.echo & sThisComputer $ " has successfully been moved to " & sDestCN & vbNewline

I am new to AutoIt and have VERY LITTLE knowledge of VB Scripting. Any help with this is appreciated.

Here's a conversion. Not tested because I'm not with my domains right now:

Opt("MustDeclareVars", 1)

Global $objOU, $objPC, $objRootDSE, $strDNSDomain
Global $sSourceCN, $sDestCN, $objNet, $sThisComputer, $sMsg

; Find this computer name
$objNet = ObjCreate("WScript.NetWork")
$sThisComputer = $objNet.ComputerName

; Get AD details
$objRootDSE = ObjGet("LDAP://RootDSE")
$strDNSDomain = $objRootDSE.Get("DefaultNamingContext")

; Set query source and destination
$sSourceCN = "LDAP://CN=" & $sThisComputer & ",OU=Computers," & $strDNSDomain
$sDestCN = "LDAP://OU=Division,OU=Region,OU=City,OU=Computers," & $strDNSDomain

; Move computer object
$objOU = ObjGet($sDestCN)
$objPC = $objOU.MoveHere($sSourceCN, "")

; Report results
$sMsg = "Moving computer account:" & @CRLF & _
        $sThisComputer & " has successfully been moved to " & $sDestCN
MsgBox(64, "Results", $sMsg)

Cheers!

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 9 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...