Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
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:
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  
Old September 5th, 2003, 09: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, 07: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: 6
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!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway