Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Update Functionality of a VB Script

Posted on 2011-09-13
3
Medium Priority
?
197 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
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 2000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

927 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