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