Solved

Update Functionality of a VB Script

Posted on 2011-09-13
3
187 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
  • 3
3 Comments
 
LVL 17

Expert Comment

by:StrifeJester
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now