Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


RE: 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 >> RE: Move Computer Account
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: <<   < prev  1 [2]
Login
Message << Older Topic   Newer Topic >>
 RE: Move Computer Account - 8/11/2006 12:01:43 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Try this: (connecting via RootDSE)


      

_____________________________

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

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 21
 
 RE: Move Computer Account - 8/11/2006 4:58:36 AM   
  cjwallace

 

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

So the script above is a seperate script to the one that moves the workstation to a new OU based on the default Gateway?


Thanks for your continued help

(in reply to Snipah)
 
 
Post #: 22
 
 RE: Move Computer Account - 8/11/2006 5:05:26 PM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Sorry, it was incomplete.... this script (untested) is complete with:

- Define vars
- Retrieve Default gateway
- Base a select[1] on the Default gateway
- within that select[1], set the VLAN and call the function to determine the VLAN's ADsPath (select[2])
- With select[2] call the function to move the PC to that VLAN office

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

'On Error Resume Next
 
'*** Define vars
Const ADS_SCOPE_SUBTREE = 2
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set oRootDSE = GetObject("LDAP://RootDSE") 'connect to the ultimate root / toplevel
Set DNSDomain = GetObject("LDAP://" & oRootDSE.Get("DefaultNamingContext"))


'*** Retrieve the Default gateway
DefaultGateway = Empty
Dim oDG, oDGs, WMI
Set WMI = GetObject("winmgmts:\\" & strComputer & "\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


'*** Select per Default gateway (select[1])
Select Case DefaultGateway
Case "10.10.0.1"
funcSelectVLAN "VLAN10" 'call the function to select the VLAN office' ADsPath
Case Else
MsgBox "Sorry, wrong Default Gateway..." & vbcrlf & vbcrlf & "This script will terminate"
Wscript.Quit
End Select 'end select[1]
 

'*** Function to select the VLAN Office' ADsPath
Function funcSelectVLAN(strVLAN)
DNSDomain.Filter = Array("OrganizationalUnit")
'Select per OU (select[2])
Select Case strVLAN
Case "VLAN10"
 For Each objChildObject In DNSDomain
  tempvarOU = Mid(objChildObject.ADsPath,11,6) 'to identify the 6 characters from VLAN**
   strVLANOUPath = objChildObject.ADsPath
  If (strVLAN = tempvarOU) Then
   funcMoveItHere strComputer strVLANOUPath 'call the function to move it to the VLAN10 container
   objComputer.Put "Location" , "VLAN10 Lower Ground Floor"
   objComputer.SetInfo
  End If
 Next
Case Else
 MsgBox "Invalid VLAN environment selected" & vbcrlf & vbcrlf & "This script will terminate"
 Wscript.Quit
End Select 'end select[2]
End Function


'*** Function to actually move the PC
Function funcMoveItHere(strComputer, strVLANOUPath)
objCommand.CommandText = "SELECT ADsPath FROM 'LDAP://" & DNSDomain & "' WHERE objectCategory='computer' AND name='" & strComputer & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
  strADsPath = objRecordSet.Fields("ADsPath").Value
  Set objOU = GetObject(strVLANOUPath)
  intReturn = objOU.MoveHere(strADsPath, vbNullString)
objRecordSet.MoveNext
Loop
End Function

_____________________________

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

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 23
 
 RE: Move Computer Account - 8/17/2006 11:28:53 PM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi Snipah, sorry its taken me so long to reply been busy dealing with other network issues.

Ok so i am picking this back up again and in not a very good way

Ok two issues here, when i run the code as is, i get the following message

Line 53
Char 31

Expected end of statement

Second , i have been trying to work out in my head with your code how i add in more than one gateway based on your code, we have 7 Gateways and based on that Gateway you will go into 1 of 7 OU's within AD

I have been pulling the script apart to fix the first issue but no joy so far.

If you can shine some light on it , that would be fab


Thanks in advance

(in reply to Snipah)
 
 
Post #: 24
 
 RE: Move Computer Account - 8/18/2006 1:58:07 AM   
  Snipah


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

1) You as Senior member should've seen the line 53 error: forgot the comma.....(calling a function with more then 1 var needs to be seperated with a comma)

Line 53 must be: funcMoveItHere strComputer, strVLANOUPath

2) To have multiple selections, best is to first read some more about the Select Case statement...then add more Case statements...

Select Case DefaultGateway
Case "10.10.0.1"
[...]
Case Else
[...]
End Select 'end select[1]


'*** Function to select the VLAN Office' ADsPath
Function funcSelectVLAN(strVLAN)
[...]
Select Case strVLAN
Case "VLAN10"
[...]
Case Else
[...]
End Select 'end select[2]
End Function



Grtz

_____________________________

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

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 25
 
 RE: Move Computer Account - 8/18/2006 2:15:29 AM   
  cjwallace

 

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

I know my thing says Senior member but i can assure you i am still very much a beginner and learning all the time from people like you i just wish my job did not need me to do such advanced things with scripts

You guys are like scripting gods in my eyes , anyway back to the task.

Doh about line 53 and yes i probably should have picked it up your right ,
but thanks for pointing it out , and also for the amendments to the script


I will give it another go and let you know how i get on.

Cheers

Craig

(in reply to Snipah)
 
 
Post #: 26
 
 RE: Move Computer Account - 8/18/2006 2:22:50 AM   
  Snipah


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


I did not mean to offend you with that remark....with the scripts you created and your help on the forum you are defenitly not a beginner!

Just holla when you need something...that is why we are here for...


_____________________________

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

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 27
 
 RE: Move Computer Account - 8/18/2006 2:33:46 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi Snipah, no no mate please dont think i was offended because i was not , i could see your point 100%


I do seem to want to do some complex stuff with scripts but i really am still learning.


Anyway thanks for all the help you give me.

I will post back with the results of how i am getting on with it

Thanks mate

(in reply to Snipah)
 
 
Post #: 28
 
 RE: Move Computer Account - 8/18/2006 10:12:47 PM   
  cjwallace

 

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

Ok so i have changed the script to include all my VLANS,

When i run the script i do not get any error messages but the script is not moving my machine from where ever it is in AD to the localtion i want it to go to

Any ideas?

Thanks again for your time



      

[/size][/font]

< Message edited by cjwallace -- 8/18/2006 10:15:31 PM >

(in reply to cjwallace)
 
 
Post #: 29
 
 RE: Move Computer Account - 8/19/2006 12:19:44 PM   
  Snipah


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

1) The following depends on the charactistics of the following string: VLAN** (where * are numerical)

tempvarOU = Mid(objChildObject.ADsPath,11,6) 'to identify the 6 characters from VLAN**


2) the following must be changed then aswell....

Case "VLAN10(Servers & IT)"

must become:

Case "VLAN10"    ' This merely to have a standard size of the VLAN string....since the descripton (eg. Servers & IT) may vary, and that will be harder to read from the AD


3) I would like to set the following in a seperate sub to only define those settings once. This will mean at calling time of the funcSelectVLAN, I will ad another entry: Location, then you can update per VLAN and set the appropiate Location, without having to have the code repeated

Hope it makes sense

< Message edited by Snipah -- 8/19/2006 12:29:03 PM >


_____________________________

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

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 30
 
 RE: Move Computer Account - 8/20/2006 2:39:32 AM   
  cjwallace

 

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

I will make the changes and try it in the office tomorrow.

Would would be the best way of me approching the sub you are talking about?

Many thanks

(in reply to Snipah)
 
 
Post #: 31
 
 RE: Move Computer Account - 8/20/2006 2:57:59 AM   
  cjwallace

 

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

I have just jumpped on to a machine in work from home to change the script as you said.

It is still running with no errors but not moving the machine

Thanks for your continued help on this

(in reply to cjwallace)
 
 
Post #: 32
 
 RE: Move Computer Account - 8/20/2006 3:13:08 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
I have added the function (no longer a sub) and re-written it completely...now it is way easier to read and implement....


      

Try putting a MsgBox in front of this line:
  funcMoveItHere strComputer, strVLANOUPath 'call the function to move it to the VLAN10 container

Mainly to see if the function is calling with all the vars filled.

You could also place a few MsgBoxes in the funcMoveItHere Function to see if the function is running with alle the vars expected...

Good luck...

< Message edited by Snipah -- 8/20/2006 3:23:30 AM >


_____________________________

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

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 33
 
 RE: Move Computer Account - 8/20/2006 3:55:21 AM   
  cjwallace

 

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

for the updated code

Ok i have run the code, still no errors and not moving the machine account. also i popped a msgbox in where you said but it never displayed

very odd. i am going to have a further play with it , but if you can think of anything else we can try that would be great

Thanks mate for your time today

Craig

Update

ok if i add a msgbox "test1" to funcMoveItHere strComputer, strVLANOUPath 'call the function to move it to the VLAN10 container
it is not returning anything

if i add a msgbox "test2" to Function funcMoveItHere(strComputer, strVLANOUPath)
it does return test2

so something is going on i think in the Function funcIdentifyAndSetLocation(strVLAN, strVLANLocation)

Anyway thought i would pass it on in case it helps

< Message edited by cjwallace -- 8/20/2006 4:01:17 AM >

(in reply to Snipah)
 
 
Post #: 34
 
 RE: Move Computer Account - 8/20/2006 8:04:33 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
Now, I fully rescanned the entire script multiple times....and (hopefully) fixed some untied items......


      

The pain is, I cannot test it...since we never move PC's to different OU's, therefor that functionality has been disabled to prevent scriptkiddies from altering the AD...

_____________________________

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

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 35
 
 RE: Move Computer Account - 8/21/2006 12:34:19 AM   
  cjwallace

 

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

I have tried the code but still the same , no error messages et etc

The one thing i was confused with was

Set oRootDSE = GetObject("LDAP://RootDSE") 'connect to the ultimate root / toplevel

just wondering why www.visualbasicscript .com was there , i changed it it

Set oRootDSE = GetObject("LDAP://RootDSE") 'connect to the ultimate root / toplevel


I feel we are so close to getting this sorted

< Message edited by cjwallace -- 8/21/2006 3:32:10 AM >

(in reply to Snipah)
 
 
Post #: 36
 
 RE: Move Computer Account - 8/22/2006 1:52:38 AM   
  cjwallace

 

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


Hi guys,

I have been trying to get this to work but been having much luck.

If anyone can shine some light on this that would be great

Thanks in advance

(in reply to cjwallace)
 
 
Post #: 37
 
 RE: Move Computer Account - 8/22/2006 8:06:48 AM   
  Snipah


Posts: 1343
Score: 6
Joined: 11/1/2004
From: Netherlands
Status: offline
it said visualbasicscript because this forum automatically creates links from LDAP addresses....

yeah...i think this needs a fresh eye on it....

_____________________________

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

http://www.visualbasicscript.com

(in reply to cjwallace)
 
 
Post #: 38
 
 RE: Move Computer Account - 9/3/2006 7:55:35 AM   
  cjwallace

 

Posts: 491
Score: 0
Joined: 3/5/2005
From: United Kingdom
Status: offline
Hi guys. just picking this script up again.

Snipah did a wonderful job so with helping me to try and get this script to run.

Can i put this script back up for some help to try and get it working?

Thanks to anyone in advance who take the time to help

(in reply to Snipah)
 
 
Post #: 39
 
 
Page:  <<   < prev  1 [2]
 
  

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 >> RE: Move Computer Account Page: <<   < prev  1 [2]
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