|
|
|||||||||
|
|||||||||
|
|||||||||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Good morning. I've been tasked to create a VBScript to automate user moves from one Active Directory OU to another OU based on output data contained in a two column .CSV file. This file would contain information pertaining to whether it was moving them to the computer account or user account OU where the users would further need to go into a laptop or desktop container nested within the either OU. Meaning, within the 2 .csv files will be 2 fields containing user name and category (Laptop or Desktop). The second would have the computer name and category (Laptop or Desktop). I decided to break the .csv files into two so one would be strictly for User Account moves and the second would be for Computer Account moves as we have separate OU's for each.
My dilemma is this, I can get the constants and variables listed, I can get the script to locate the data file and create a log file if there is none, however, parsing the data and actually doing the move is what's bogging me down. Would you possibly be able to lend and eye and some ideas to get me back on track? Here is my script so far. Thanks in advance. I can forward the csv upon request. Option Explicit On Error Resume Next Const sourceFilePath = "c:\data\CDA3UsrAsset.csv" 'Path to source file. Const DeskOUPath = " ou=CmpAccts,ou=Corp,ou=HersheyArea,ou=Desktops,dc= Ross,dc=Com" 'Path to Desktop OU. Const LapOUPath = " ou=CmpAccts,ou=Corp,ou=HersheyArea,ou=Laptops,dc=R oss,dc=Com" 'Path to Laptop OU. Const oldOUPath = "ou=Corp,dc=Ross,dc=Com" 'Path to Old OU. Const sOutputFile = "c:\data\UserMove.log" 'output log file Const ForReading = 1, ForWriting = 2, ForAppending = 8 ' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''' ' GLOBAL VARIABLES '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''' Dim WSHShell, FS, InFile, OutFile, inputlines, inputdata() Dim filFound(), Category(), Username(), SplitArray Dim sLine, sResult, i Dim afile Dim strMsg, str4Users, strCat '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''' ' PROCEDURES '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''''''''''''''''''''''''''''''''''''''''''''' '''''''' Set WSHShell = WScript.CreateObject("WScript.Shell") ' Check for Log File and create if none exists Set FS = CreateObject("Scripting.FileSystemObject") Set aFile = FS.CreateTextFile("sOutputFile") ' Check Data file for information to parse Set FS = CreateObject("Scripting.FileSystemObject") Set InFile = FS.OpenTextFile(sourceFilePath, ForReading) If Err.Number <> 0 Then MsgBox "Control file does not exist." & VBCRLF & _ "Please create a CSV file and run again.", vbCritical, "Error": wscript.quit(1) ' Edit log file with Error if no information exists Set OutFile = FS.OpenTextFile(sOutputFile, ForAppending, True) If Err.Number <> 0 Then MsgBox "Cannot create Log File!", vbCritical, "Error": wscript.quit(1) ' Insert Time and Date Stamp upon running OutFile.writeline "---------------------------------------------" OutFile.writeline "Processing Started - " & time & " " & date OutFile.writeline "---------------------------------------------" Load data file Call GetData(sourceFilePath) Read data from CSV into array Sub GetData(sourceFilePath) inputlines = 0 Do While InFile.AtEndOfStream <> True inputlines = inputlines + 1 ReDim Preserve inputdata(inputlines + 1) inputdata(inputlines) = InFile.readline If Err.Number <> 0 Then Exit Do Loop If Err.Number <> 0 Then inputlines = inputlines - 1 InFile.Close If inputlines = 0 Then MsgBox "Data file is empty", vbCritical, "Error" wscript.quit(1) End If Err.Clear End Sub Bind to Target OU Set objOU = GetObject(oldOUPath) Call GetData ReDim Username(inputlines) 'user accounts ReDim Category(inputlines) 'Desktop or Laptop? Parse the data from Data File Sub GetData(sourceFilePath) Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile _ (sourceFilePath, ForReading) Do Until objTextFile.AtEndOfStream <> True strNextLine = objTextFile.Readline arrServiceList = Split(strNextLine , ",") strCat = Left(Right(Category(inputlines), 6), 1) If strCat = "N" Then Call MoveUser Sub MoveUser Set objNewOU = GetObject(oldOUPath) Set objMoveUser = objNewOU.MoveHere _ ("LDAP://CN=" + UserName + "," + oldOUPath + "," + LapOUPath,"CN=" + UserName) Else Set objNewOU = GetObject(oldOUPath) Set objMoveUser = objNewOU.MoveHere _ ("LDAP://CN=" + UserName + "," + oldOUPath + "," + DeskOUPath,"CN=" + UserName) End Sub For i = 1 to Ubound(arrServiceList) Next Loop End Sub |
|
#2
|
|||
|
|||
|
Lots of code, but what goes wrong, actually???
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > VBScript OU User Moves brick wall |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|