WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Move computer between containers

Keywords: 	 dsMoveObj Move Computer Object Between Containers Different OU 

Question:

I would like to move a computer account from one container to another via a winbatch script. Any help on how this is done would be appreciated!!

Answer:

Here is an undebugged code sample to move computer object:
;***************************************************************************
;**
;**    List Computer Objects
;**
;***************************************************************************

;Load Appropriate Extender
If WinMetrics(-2) == 3 Then AddExtender("WWADS64I.DLL") ; 64-bit
Else AddExtender("WWADS44I.DLL") ; 32-bit

; Construct the full domain ADSI path.
ServerDn = dsGetProperty("LDAP://rootDSE", "serverName")
ServerName = ItemExtract(1, ServerDn, ",")
ServerName = ItemExtract(2, ServerName, "=")
ServerDn = dsGetProperty("LDAP://rootDSE", "defaultNamingContext")
ServerPath = "LDAP://%ServerName%/%ServerDN%"

; Find the computers path
ComputerPaths = dsFindPath(ServerPath, "(&(objectCategory=computer))")
objComputerPath = AskItemlist('Computer Objects', ComputerPaths, @TAB, @UNSORTED, @SINGLE )

;***************************************************************************
;**
;**    List OU Objects
;**
;***************************************************************************
;Load Appropriate Extender
If WinMetrics(-2) == 3 Then AddExtender("WWADS64I.DLL") ; 64-bit
Else AddExtender("WWADS44I.DLL") ; 32-bit

; Construct the full domain ADSI path.
ServerDn = dsGetProperty("LDAP://rootDSE", "serverName")
ServerName = ItemExtract(1, ServerDn, ",")
ServerName = ItemExtract(2, ServerName, "=")
ServerDn = dsGetProperty("LDAP://rootDSE", "defaultNamingContext")
ServerPath = "LDAP://%ServerName%/%ServerDN%"

; Find the OU paths
OUPaths = dsFindPath(ServerPath, "(&(objectCategory=organizationalunit)(ou=*))")
targetOUpath = AskItemlist('OU Objects', OUPaths, @TAB, @UNSORTED, @SINGLE )


;***************************************************************************
;**
;**                     dsMoveObj
;**   This function moves an ADSI object from one container to another.
;**   The object can optionally be renamed by providing a new name in the third parameter
;**
;***************************************************************************
dsMoveObj(objComputerPath, targetOUpath , "")

Article ID:   W15389
File Created: 2012:11:16:11:00:38
Last Updated: 2012:11:16:11:00:38