Jordi wrote:
>I am looking to automate the process of moving computers that get into our
> computers container. I've found scripts that talk about moving computers,
> but is it possible to scan the first 4-5 characters of the computer
> account
> name an move it based on that.
>
> Example:
>
> Computer name starts with...
>
> PS-E... would get moved to a specific OU
> PS-S... would get moved to a different OU
> PS-T... would get moved to a different OU
>
>...snip
In brief, the code to move the computers could be similar to below:
===============
Option Explicit
Dim objPSE, objPSS, objPST
Dim objContainer, objComputer, strOU
' Bind to the target OU's (do this once).
Set objPSE = GetObject("LDAP://ou=PSE,ou=West,dc=MyDomain,dc=com")
Set objPSS = GetObject("LDAP://ou=PSS,ou=West,dc=MyDomain,dc=com")
Set objPST = GetObject("LDAP://ou=PST,ou=West,dc=MyDomain,dc=com")
' Bind to container object.
Set objContainer = GetObject("LDAP://cn=Computers,dc=MyDomain,dc=com")
' Filter on computer objects.
objContainer.Filter = Array("computer")
' Enumerate all computers in container.
For Each objComputer In objContainer
' Check first 4 characters (upper case) of NetBIOS Name.
strOU = Left(UCase(objComputer.sAMAccountName), 4)
Select Case strOU
Case "PS-E"
objPSE.MoveHere objComputer.AdsPath, vbNullString
Case "PS-S"
objPSS.MoveHere objComputer.AdsPath, vbNullString
Case "PS-T"
objPST.MoveHere objComputer.AdsPath, vbNullString
End Select
Next
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--