Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old September 5th, 2003, 10:21 AM
rossanova rossanova is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Harrisburg, PA
Posts: 1 rossanova User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy VBScript OU User Moves brick wall

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

Reply With Quote
  #2  
Old October 15th, 2003, 08:40 AM
m_lazor m_lazor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Luxembourg
Posts: 156 m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level)m_lazor User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Lots of code, but what goes wrong, actually???

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > VBScript OU User Moves brick wall


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek