Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Move Computer Accounts from Computer Container

Reply
Thread Tools Display Modes

Move Computer Accounts from Computer Container

 
 
Jordi
Guest
Posts: n/a

 
      09-27-2008
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

Here are the links to the information i've found so far...

http://www.microsoft.com/technet/scr...1.mspx?pf=true

http://www.microsoft.com/technet/scr...t.mspx?pf=true

http://www.microsoft.com/communities...=en-us&m=1&p=1

http://www.microsoft.com/communities...=en-us&m=1&p=1

Much Appreciated,

Jordi



 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      09-27-2008
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
--


 
Reply With Quote
 
Jordi
Guest
Posts: n/a

 
      09-29-2008
Brilliant!! This is exactly what i was looking. Thanks Richard!!

"Richard Mueller [MVP]" wrote:

> 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
> --
>
>
>

 
Reply With Quote
 
Junior Member
Join Date: Feb 2012
Posts: 1

 
      02-09-2012
This is a great script and could be very useful...IF I can get it to work...

I've changed the lines for my environment but I'm gettting the following:

(null): there is no such object on the server.

Exit code: 0 , 0000h

Any help would be greatly appreciated!!

Thanks!
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Move computer accounts from one domain to another Helge Scripting 0 03-28-2007 12:10 AM
Re: Delegation: Move Computer accounts between OUs Jorge de Almeida Pinto [MVP] Active Directory 0 01-20-2006 06:19 PM
Please Help- How to restrict anyone from creating computer accounts in default computer container? Sunny Active Directory 2 12-07-2005 10:41 AM
Move computer accounts into OU Angryblack Scripting 0 04-26-2005 02:44 PM
move computer accounts to a new OU kim7465 Scripting 1 11-28-2003 12:07 AM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59