Page 1 of 1 1
Topic Options
#137790 - 2005-04-13 07:30 AM move computer to new container in AD
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
I have been looking over the inContainer, TranslateName, ADsearch.

When new computers are added to our AD, the computer is put in a "default" container. However, we need it to be moved to it's permanent container. I want to automate this through the login script for our techs so after the computer is joined, it will be moved to the new container at next login.
Any ideas or suggestions?

Thanks!
_________________________
John
LM Contractor
One of the 2 dads

Top
#137791 - 2005-04-13 09:41 AM Re: move computer to new container in AD
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11631
Loc: CA
Why not put it in the correct container when you join the AD?

NETDOM.EXE should be able to do that for you.

Top
#137792 - 2005-04-13 12:36 PM Re: move computer to new container in AD
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
NTDOC,
Thanks for the reply.
We are only one of many sites in the OU. As it was explained to me, the workstations when added to the domain by the technician will default to a 'generic' container. After the computer is added, it has to be moved by the tech to the permanent OU.
If there is a better way for us to add the computers to the domain, then I am all ears. I will dig through my book again and see if I can find something else to work with.
I know I have seen some scripts on moving workstations to different OU's and thought they were in the kix forum, but I cant find those references so it could have been a different forum
Thanks for the info!
_________________________
John
LM Contractor
One of the 2 dads

Top
#137793 - 2005-04-13 02:22 PM Re: move computer to new container in AD
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
here is some code to look through.

Code:

$newName = $ComputerBox.text
$domain = $DomainBox.text
$password = $PasswordBox.text
$user = $AdminBox.text
$OU = $OUCombo.text
$JOINType = 1 + 2 + 32

$objNetwork = CreateObject("WScript.Network")
if not @error
$strComputer = $objNetwork.ComputerName
$objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\"+$strComputer+"\root\cimv2:Win32_ComputerSystem.Name='"+$strComputer+"'")
$ReturnValue = $objComputer.JoinDomainOrWorkGroup($Domain, $password, $Domain+"\"+$user, $OU, $JOINtype)
If $ReturnValue
Status("Failed joining "+@wksta+" to "+$domain)
Status($ReturnValue)
return
EndIf
Status("waiting 15 seconds")
sleep 15

Status("Renaming")
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + "\root\cimv2")
$colComputers = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each $objComputer in $colComputers
$err = $objComputer.Rename($NewName, $password, $Domain + "\" + $user)
If $err
Status("Failed Renaming "+@wksta+" to "+$NewName)
Status($err)
return
endif
Next



I pulled this from an existing kixform I'm developing


Edited by Radimus (2005-04-13 02:24 PM)
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#137794 - 2005-04-13 02:23 PM Re: move computer to new container in AD
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Heres a snippet of our code for moving workstations, basically you bind to the target OU, then "move" from the source ou into that. We use this code to have NT4 workstations "join and move themselves" into AD.

If you have any questions, feel free to ask.

Code:

$WKSTA = "hostname"
$USERID = "domain\userid"
$PASSWORD = "********"
$SERVER = "dcservername"

$SOURCEOU = "LDAP://CN=$WKSTA,CN=COMPUTERS,DC=XXX,DC=YYY,DC=ZZZ,DC=CA"
$TARGETOU = "LDAP://$SERVER/OU=AAA,OU=BBB,OU=CCC,DC=XXX,DC=YYY,DC=ZZZ,DC=CA"

;======================
; GET HANDLE TO LDAP...
;======================

$ROOT = GETOBJECT("LDAP:")

IF @ERROR
EXIT 102
ENDIF

;======================
; BIND TO TARGET OU ...
;======================

$ADS_SERVER_BIND = 512

$TARGET = $ROOT.OPENDSOBJECT($TARGETOU, $USERID, $PASSWORD, $ADS_SERVER_BIND)

IF @ERROR
EXIT 103
ENDIF

;=============================================
; MOVE WORKSTATION FROM SOURCE OU TO TARGET OU
;=============================================

$= $TARGET.MOVEHERE($SOURCEOU,"CN=$WKSTA")

IF @ERROR
EXIT 104
ENDIF


Top
#137795 - 2005-04-13 02:28 PM Re: move computer to new container in AD
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
btw - you don't "need" to bind to a particular server, or even provide credentials. We needed to though - to avoid replication issues between the time the machine is joined to AD (using netdom), and when we wanted to move the machine (which is right after that).

The reason for the funny error-codes is because this code was part of a tivoli-job.

-Shawn

Top
#137796 - 2005-04-13 02:53 PM Re: move computer to new container in AD
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Why not simply create the computer account in the correct OU before joining it?
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137797 - 2005-04-13 02:59 PM Re: move computer to new container in AD
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
You asking me ? Because a) we wanted a fully automated solution, one that didn't involve pre-creating the accounts in the proper OU and b) These are NT4 machines, and NETDOM for NT4 (the last version of NETDOM for NT4) doesn't support joining into an OU. So we needed this "after-bit" to do "the move" after NETDOM.

-Shawn

Top
#137798 - 2005-04-13 03:07 PM Re: move computer to new container in AD
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
That's just it. If the account is created at the right OU before the NT4 computer is joined, it joins in at the right OU.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137799 - 2005-04-13 03:10 PM Re: move computer to new container in AD
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Ok the truth then ;0) - I didn't feel like doing an inventory on 10,000 machines, then write some script that pre-creates all these accounts, and deal with all the failed attempts with unjoins and rejoins. ;0)
Top
#137800 - 2005-04-13 03:10 PM Re: move computer to new container in AD
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
Quote:

Why not simply create the computer account in the correct OU before joining it?




Joining a new workstation to a domain using AD puts the workstation into the main computer container by default. each of our OU have GPO's applied and certain workstations must go into the respective OU. It is my understanding that GPO can not be applied to the default computer OU...
_________________________
John
LM Contractor
One of the 2 dads

Top
#137801 - 2005-04-13 03:18 PM Re: move computer to new container in AD
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Maybe you missed what I said. If you create the computer account in the right OU BEFORE you join it to the domain, it will not end up in the DEFAULT container. We have dozens of techs doing it that way ever day.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#137802 - 2005-04-13 03:56 PM Re: move computer to new container in AD
Radimus Moderator Offline
Moderator
*****

Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
Quote:

Ok the truth then ;0) - I didn't feel like doing an inventory on 10,000 machines, then write some script that pre-creates all these accounts, and deal with all the failed attempts with unjoins and rejoins. ;0)




Me neither
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#137803 - 2005-04-13 04:16 PM Re: move computer to new container in AD
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Quote:


Joining a new workstation to a domain using AD puts the workstation into the main computer container by default.





Well, thats true when joining a machine using NETDOM on NT4, the Win2K and above version of NETDOM does allow you to join directly into an OU. We probably would have done it this way if we could (but we couldn't).

The other thing is, we wanted to fully automated our NT4 migration. Since we didn't have an inventory of machines (and didn't want to do one), our machines just magically "pop" into AD, as they are migrated. No need to have technicians pre-create accounts (and maybe screwing things up). No need to have our AD administrators on "stand-by" 7/24 ... we didn't have that luxury anyways.

-Shawn

Top
#137804 - 2005-04-14 05:49 AM Re: move computer to new container in AD
jechilt Offline
Starting to like KiXtart

Registered: 2000-12-01
Posts: 102
Loc: Denver Colorado
Quote:

Maybe you missed what I said. If you create the computer account in the right OU BEFORE you join it to the domain, it will not end up in the DEFAULT container. We have dozens of techs doing it that way ever day.



Sorry Les, did not catch that first time around.
I am trying to build a script that will look at our SQL database and check if the computername has been used in the past. If not, have it look at AD to double check and then add the new name. Will add the account to the new OU and then have the tech add it to the domain. I am curious though how I can do this if the computer is not yet part of the domain, or if it is possible to run from that machine. I am thinking I need a seperate script that is already on the domain. Any ideas or suggestions?
_________________________
John
LM Contractor
One of the 2 dads

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 302 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.068 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org