Solved

Update Functionality of a VB Script

Posted on 2011-09-13
3
192 Views
Last Modified: 2012-05-12
I have the below script that I would like to add some king of progress bar and an output file that shows all the accounts it processes.  I was wondering if someone could provide some simple code to do this?
'On Error Resume Next

Set oContainer = GetObject("LDAP://OU=test,OU=test1,OU=Users,DC=test,DC=com")
Set oCanadaGrp = GetObject("LDAP://CN=APP_Canada_Assoc,OU=GO,OU=Applications,OU=Groups - Security,OU=Admin,DC=test,DC=com")
Set oUSAGrp = GetObject("LDAP://CN=APP_USA_Store_Assoc,OU=GO,OU=Applications,OU=Groups - Security,OU=Admin,DC=test,DC=com")
For Each object In oContainer
        Found = False
        If LCase(object.Class) = "user" Then
                If LCase(object.co) = "united states" Then 
                        For Each member In oUSAGrp.members
                                If LCase(member.ADSPath) = LCase(object.ADSPath) Then 
                                	Found = True
                                	Exit For
                                End If
                        Next
                        If Not Found Then oUSAGrp.Add(object.ADSPath)
                End If
                If LCase(object.co) = "canada" Then
                        For Each member In oCanadaGrp
                                If LCase(member.ADSPath) = LCase(object.ADSPath) Then
                                	Found = True
                                	Exit For
                                End If
                        Next
                        If Not Found Then oCanadaGrp.Add(object.ADSPath)
                End If
        End If
Next

Open in new window

0
Comment
Question by:seaninman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 17

Expert Comment

by:StrifeJester
ID: 36530003
Unfortunately there is no progress bar available in VB Script that I know of.  VB.net would have a progress bar available.  As far as a file for the output I will add some lines and post the code back for you.
0
 
LVL 17

Accepted Solution

by:
StrifeJester earned 500 total points
ID: 36530111
Here is the new script.  After is does the .Add it will write a line to the logfile containing the same information.
'On Error Resume Next
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oLogFile = oFS.CreateTextFile("C:\logfilename.txt",True)
Set oContainer = GetObject("LDAP://OU=test,OU=test1,OU=Users,DC=test,DC=com")
Set oCanadaGrp = GetObject("LDAP://CN=APP_Canada_Assoc,OU=GO,OU=Applications,OU=Groups - Security,OU=Admin,DC=test,DC=com")
Set oUSAGrp = GetObject("LDAP://CN=APP_USA_Store_Assoc,OU=GO,OU=Applications,OU=Groups - Security,OU=Admin,DC=test,DC=com")
For Each object In oContainer
        Found = False
        If LCase(object.Class) = "user" Then
                If LCase(object.co) = "united states" Then 
                        For Each member In oUSAGrp.members
                                If LCase(member.ADSPath) = LCase(object.ADSPath) Then 
                                        Found = True
                                        Exit For
                                End If
                        Next
                        If Not Found Then 
                        	oUSAGrp.Add(object.ADSPath)
                        	oLogFile.WriteLine object.ADSPath
                        End If
                End If
                If LCase(object.co) = "canada" Then
                        For Each member In oCanadaGrp
                                If LCase(member.ADSPath) = LCase(object.ADSPath) Then
                                        Found = True
                                        Exit For
                                End If
                        Next
                        If Not Found Then 
                        	oCanadaGrp.Add(object.ADSPath)
                        	oLogFile.WriteLine object.ADSPath
                        End If
                End If
        End If
Next

Open in new window

0
 
LVL 17

Expert Comment

by:StrifeJester
ID: 36530169
To expand on the progress bar thing the reason is that it runs the command 1 line at a time and stores the information so if I remember right there would be no way to thread off a progress bar.  Also because your query is happening on the fly for the groups the only way to build something similar to progress bar would be to fully enumerate the AD group and then use the accounts total as an index to go off of.  Then you could build it in to pop up a box with percentages but again without being able to thread off the progress bar as a separate workload called from the main script the most you will get is a log file that shows the accounts processed.  You could as mentioned in my first post create a thread for the progress bar as soon you start the for loop since it would then enumerate the total number of users and you can increment the progress bar based on the current user it is on and gather a percentage there to feed at it.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question