Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Move Computer Account

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,36824
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Move Computer Account
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1] 2   next >   >>
Login
Message << Older Topic   Newer Topic >>
 Move Computer Account - 8/8/2006 8:02:08 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi guys. Ok this is going to be a multipart post.

Ok so i want to move my computers from one OU to another.

Now the script below needs to know the OU where the computer is and then the OU the computer needs to be moved to.

What i would like the script to do is find the machine where ever it is in AD and then move it to an OU

Set objNewOU = GetObject("LDAP://OU=Finance,DC=fabrikam,DC=com")

Set objMoveComputer = objNewOU.MoveHere _
  ("LDAP://CN=atl-pro-03,CN=Computers,DC=fabrikam,DC=com", "CN=atl-pro-03")

Any ideas?

Many thanks

Craig


Sorry i meant to say this script will be run when the computer starts up.

< Message edited by cjwallace -- 8/8/2006 8:03:15 PM >
 
 
Post #: 1
 
 RE: Move Computer Account - 8/8/2006 9:35:22 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
in fact i have this old script i forgot about

=====================
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName


Set
objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer &
"\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer &
"'")
Set objOU = GetObject("LDAP://OU=WORKSTATIONS,OU=LONDON,OU=WORKSTATIONS,OU=EUROPE,OU=WITHERS,DC=WITHERS,DC=NET")
intReturn = objOU.MoveHere _
(
"LDAP://CN="& strComputer &",OU=LONDON WORKSTATIONS,OU=WITHERS WORKSTATIONS,DC=WITHERS,DC=NET", vbNullString)

===================

So with the above information does anyone know how i might get the script to go out and find the workstation and move it from its current OU to the OU that i want?

Many thanks

(in reply to cjwallace)
 
 
Post #: 2
 
 RE: Move Computer Account - 8/8/2006 9:42:05 PM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Hiya,

Try this: (as a part one...) I will retrieve the full path, but this is a head start....kinda busy all of a suddon....brb


      


_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 3
 
 RE: Move Computer Account - 8/8/2006 9:51:15 PM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Let me understand it better:

The script needs to know at logintime, where he is configured, and if it equals a certain pattern, MoveIt to a defined container....

S.


_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 4
 
 RE: Move Computer Account - 8/8/2006 10:05:46 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Snipah:

You have got it in one. What i am trying to do is move the computer account at logon to a certain OU based on the Gateway. This is a one time process and the script will only run during SMS Server State Restore phase.

I will take a look at the script you have just posted

Many thanks for your help so far

(in reply to Snipah)
 
 
Post #: 5
 
 RE: Move Computer Account - 8/8/2006 11:39:40 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Just whille Snipah is not around can anyone else shine some light on what i am trting to do?

Thanks very much

(in reply to cjwallace)
 
 
Post #: 6
 
 RE: Move Computer Account - 8/9/2006 12:26:32 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Got it.......well almost


      


I need to some how get the value from StrComputer into "And name='MACHINENAMEHERE'"

Any ideas, everything i have tried is not right

Thanks in advance

(in reply to cjwallace)
 
 
Post #: 7
 
 RE: Move Computer Account - 8/9/2006 12:35:44 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
quick addon to your script:


objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://dc=WITHERS,dc=NET' WHERE objectCategory='computer' AND name='" & strComputer & "'"

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 8
 
 RE: Move Computer Account - 8/9/2006 12:47:28 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Excellent Snipah that now works a treat.



Ok on to the next part of this script.

Ok so here in our main office we have VLAN's lets just say VLAN 1 to 10 and each VLAN has a different Default Gateway. Now i would like the script to first workout what VLAN it is on based on the default Gateway and then based on that information use the above script to move the workstation to a OU

I am going to do some searching and some playing about but if you know a way to grab the default Gateway and run code based on that , that would be fab

Many thanks for your help in advance

Craig

(in reply to Snipah)
 
 
Post #: 9
 
 RE: Move Computer Account - 8/9/2006 1:25:44 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
CJWallace,

There are several ways to determine the IP addresses....


      

---------------------------------


      

You could then use something like:


      

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 10
 
 RE: Move Computer Account - 8/9/2006 1:35:34 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Excellent Thank you

Ok

So i am going to use this but i know it is wrong so far.


      

(in reply to Snipah)
 
 
Post #: 11
 
 RE: Move Computer Account - 8/9/2006 1:54:45 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
not to worry i got it

[code]
Function DefaultGateway
DefaultGateway = Empty
Dim oDG, oDGs, WMI
Set WMI = GetObject("winmgmts:\\.\root\cimv2")
Set oDGs = WMI.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each oDG in oDGs
If Not IsNull(oDG.DefaultIPGateway) Then
If Not oDG.defaultIPGateway(0) = "0.0.0.0" Then
DefaultGateway = oDG.DefaultIPGateway(0)
Exit For
End If
End If
Next
End Function
Select Case DefaultGateway
Case "10.10.0.1"
MsgBox "test"
Case "10.2.1.254"
'Do something
End Select
[/code}

Ok now on to the next part of putting it all together

Will post back

Cheers

Craig

(in reply to cjwallace)
 
 
Post #: 12
 
 RE: Move Computer Account - 8/9/2006 1:58:27 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
double post??

let me know which one to remove

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 13
 
 RE: Move Computer Account - 8/9/2006 2:27:42 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
ok so here is the finished code. I have only put on VLAN & Default Gateway


      


Thanks to everyone who replied especially Snipah

(in reply to Snipah)
 
 
Post #: 14
 
 RE: Move Computer Account - 8/9/2006 5:34:55 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
ok so here is the next part of the puzzle.

Based on the code above i would like to add the following bit of code to each of the code for my VLANS but changing the text for each VLAN

Set objComputer = GetObject _
   ("LDAP://CN=atl-dc-01,CN=Computers,DC=fabrikam,DC=com")
objComputer.Put "Location" , "VLAN21 1st Floor"
objComputer.SetInfo

I cant see from my code above how i might slip this in. it is the whole LDAP part i am having trouble getting my head round because of the way the code above works

Can anyone give any direction

Thanks very much

(in reply to cjwallace)
 
 
Post #: 15
 
 RE: Move Computer Account - 8/9/2006 6:11:04 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Select Case OU

Case "VLAN10"
objComputer.Put "Location" , "VLAN10 3rd Floor"
objComputer.SetInfo

Case "VLAN21"
objComputer.Put "Location" , "VLAN21 1st Floor" 
objComputer.SetInfo

End Select

_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 16
 
 RE: Move Computer Account - 8/9/2006 6:39:48 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Snipah , thanks for the reply

ok so would my code now look like this?

Sorry not at work so cant test


      

Thanks for your help

(in reply to Snipah)
 
 
Post #: 17
 
 RE: Move Computer Account - 8/9/2006 9:49:13 PM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
The following link shows how to display the OU's

http://rallenhome.com/books/adcookbook/src/05.02-display_ou_containers.vbs.txt




_____________________________

For more information, please see the "Read me First" topic.

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 18
 
 RE: Move Computer Account - 8/9/2006 10:26:26 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi Snipah. Thanks for your reply.

I am a bit stuck on this one. no matter where i put the code below in my script it is just not changing the location field for the machine that is moved. Everything else works

Select Case OU

Case "VLAN10"
objComputer.Put "Location" , "VLAN10 3rd Floor"
objComputer.SetInfo


Any ideas?

(in reply to Snipah)
 
 
Post #: 19
 
 RE: Move Computer Account - 8/10/2006 6:17:45 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
I have tried just about every possible way to get this last part of the script working. I am just not sure what i am doing wrong , but i am doing something wrong

If anyone can give any guidance that would be fab

Many thanks

Craig

(in reply to cjwallace)
 
 
Post #: 20
 
 
Page:   [1] 2   next >   >>
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Move Computer Account Page: [1] 2   next >   >>
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts