Solved

Update Functionality of a VB Script

Posted on 2011-09-13
3
188 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 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
A short film showing how OnPage and Connectwise integration works.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 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

9 Experts available now in Live!

Get 1:1 Help Now