PDA

Click to See Complete Forum and Search --> : help with VB script to manage Exchange Distribution list management


joechurch
Aug 8th, 2008, 10:47 AM
I work for a company where we have users who travel quite a bit, and while traveling or on vacation will request of me to remove them from some Exchange Distribution lists. This is all fine and dandy, but is a pain to do manually, since most of them want the changes made at weird off hour times. I would like to work with smoeone who knows VB and or WSH who would be willing to help construct a script that can automate the process. On one hand I was thinking something that would have a gui popup asking for the user name you want to add or remote, and then another screen that would display a list of Exchange Distribution Lists you could pick, preferably have the option to select multiple DLs. Then confirm the action to add or remove. Then on the other hand, it would be nice to have something that could be done from the command line, so it can be automated and scheduled.

I guess the best option would be something that could work from a command line. I would immaging I'd be looking for something with the following input format:

To add:
dlmanage add username dlname

To remove:
dlmanage remove username dlname

(dlmanage is just a made up name, could be whatever)

So I don't know enough about VB to accomplish this on my own. I need some help and can be the beta tester to help develop a working script. We'd need a good way to input DL names, as these can be long and contain spaces, so maybe some exchange attribute that has no spaces like the group name (pre-windows 2000 name), or maybe the smtp e-mail addtress of the group?

What I am trying to accomplish here is to have a way to automate and possibly schedule distribution list management. So if a user goes on vacation I an schedule the script to remove the user from a list of Distribution lists by setting up a batch file to execute the script for each DL to remove the user from. Same thing for re-adding them, putting them back on a list of DLs.

If anyone wants to contribute and help develop this, I'm sure it would come in handy for a lot of sysadmins, and perhaps even develop into its own tool...

chris128
Aug 9th, 2008, 07:10 AM
I would help if it was VB.NET but I'm afraid I'm no good with vbscript...

joechurch
Aug 9th, 2008, 08:33 AM
Do you think this could be done in .NET? I am not a programmer, so I was just throwing out some scripting technologies I knew could do it. I don't want to limit this to just VB scripting if there are better ways to do it...

chris128
Aug 9th, 2008, 03:00 PM
Well vbscript would be good because it doesnt have any prerequisites like VB.NET does (.NET framework must be installed for a VB.NET program to run). You couldnt make a proper GUI with vbscript though... you would just be limited to the standard inputbox and msgbox.

It could definitely be done in VB.NET but I am a little puzzled as you say that you are not a programmer but in your first post you said you wanted to work with someone else on it. However, if you are not a programmer then surely you are basically just asking someone to make it for you?


Also - you say that you want to make this tool because it is a pain having to do this manually at odd times in the day but you do realise that even with a script you still need to tell it who you want to remove and from which dist list... so you couldnt just stick it in a scheduled task like you mentioned because when it ran on the schedule then how on earth would it know what it was supposed to do?

joechurch
Aug 9th, 2008, 03:04 PM
Sorry for the confusion, what I meant by "work with someone" is that I have the environment to thoroughly test it, and fine tune it. I am not a programmer, but would like to find one to work with me on designing a good solution for this task. I can't find anything else out there that would accomplish this task, and it could be a very useful tool.

chris128
Aug 11th, 2008, 12:41 PM
I dont mean to sound like I'm just hating on your idea for the sake of it but I'm a network/server admin same as you and I dont really see how this would benefit anyone but I'm always up for a little challenge so yeah I'll help you out.
Give me some more info and examples of exactly how you want this to work (be as specific and descriptive as possible) and I'll see what I can throw together when I get some time.

Please note though that normally you shouldnt really just come on here and ask people to write programs for you without doing any of it yourself first. I would also encourage you to try to learn how to do things like this yourself then in future you dont need someone else to do it for you ;)

joechurch
Aug 11th, 2008, 01:19 PM
I understand. Let me try to clarify...

Lets say you have a user who comes to you and asks to be removed from 7 specific Distribution Lists but wants to stay on 2 others. Not just that, but they want the change to be effective at midnight on a Friday. They also want to be re-added to the DLs you removed them from the following Wednesday at 2am.

Given this scenario, I do not know of any way to automate or schedule anything like this. I've never seen or heard of any tools that will let you automate or schedule DL changes like this.

So what I am proposing/asking is help from someone who can code in the appropriate language a script that be executed from command line, so that it can be batched and executed as a scheduled task. This way, you just setup a simple set of commands in a batch file and schedule it as a scheduled task on a server. To get even more fancy, maybe it would be nice to get e-mail notifications of the changes the script is making and send a copy to the user and to another e-mail address (IT staff) informing them that the changes were successful.

We get this kind of request in our company all the time, and I can't immagine that we are the only ones. We heavily use DLs in our environment and they receive thousands of e-mails to some of them each day. So think about it, if a user travels internationally (we are in the U.S), then the roaming data charges on their mobile PDA phones would be huge downloading all that e-mail. So it also saves money to do this.

Originally I thought it might be nice to have a small GUI input box asking for the username and then be presented with a list of DLs you can work on, with an option to add or remove from a user's profile, but after thinking through the process, I think a script that can be called at the command link with some variables would be better, because as I mentioned it could then be batched and scheduled.

I think this would be a great tool to have, and I know of a number of sysadmin sites the resulting script could be posted to and I'm sure it would be popular. Unless you are a control freak and want to stay up until midnight on a weekend so you can change DL membership and then get up at 2am to put peopel back on the lists...

Does that help clarify what I am thinking?

Thanks

P.S. This may just be a flaw in my thinking, but where would you go for help on something like this, it seemed natural to me to go to the vbforums... I am trying to colaborate on this project with as many people as want to join in and help, as I said I have the perfect environment for testing such a script in the real world and still have something to contribute even if I am not a "programmer"...

chris128
Aug 11th, 2008, 01:35 PM
Ah I see, makes more sense now as to why you would want to do this. I've never been in that situation, all of the dist lists at various companies I have worked for have usually been pretty static. I mean most of the time dist lists only get changed when someone new starts with the company or someone leaves.
If you want the script to email you when it has made a change then how do you want to tell it which SMTP server (and credentials) to use and which email address to send it to? It wouldnt be impossible but I think it would mean having a lot of command-line arguments etc so probably best to ignore the email idea for now. Maybe thats something that we can try and do once we get the main part of the application working.
You do understand that because this is going to be a VB.NET program, it will require you to install the .NET Framework V2.0 or above on any machine that is going to be running this program yeah? (you can download the framework from the MS website for free in case you didnt know).

joechurch
Aug 11th, 2008, 01:40 PM
Ok thants fine with me, the e-mail part was just an enhancement anyway, but I do have some VB scripts that work that can create message files that we drop into the mail pickup folders on the exchange server, so it may be easy to do, but not sure if the VB code would help or not.

As far as installing the .net framework, thats no problem, put put that on all our desktops/laptops and servers by default.

Thanks
Joe

chris128
Aug 11th, 2008, 05:20 PM
OK I'll see what I can do ;)

chris128
Aug 11th, 2008, 07:28 PM
Alright so I put this together (read the notes below before running it) but its not finished yet...
VB Project Files (http://www.cjwdev.co.uk/progs/DLManage/DLManage-ProjectFiles.zip)

It does pretty much everything you asked for but I need to make it a bit more robust etc.
You run it via the command line and must enter 5 arguments using the following syntax:
DLManage.exe [Add/Remove] [User] [DistList] [DomainAdminUsername] [DomainAdminPassword]
Example:
DLManage.exe add DSmith "All Employees" mydomainadmin myadminpasswrd
I also needed a way for you to be able to enter your domain name but didnt want to add yet another command line argument so instead if uses an INI file. At the moment (because its not finished) all you need to do is create an INI file in the same directory that the program is being run from and call it Config.INI. In here just type in the LDAP path for your domain. e.g - if your domain was named MyDomain.com then you would type this into the INI file: LDAP://DC=MyDomain,DC=com then save and close it.

So yeah give it a go and let me know if this is the kinda thing you were after. I'll send you a PM with some other quick questions in a moment as well.

Chris

joechurch
Aug 12th, 2008, 07:00 AM
I am thrilled to say that this works perfectly!!! To be honest, I really thought it would take several steps of trial and error, but your first release worked perfectly! This is absolutely what I was hoping for, with this I can batch and schedule DL changes, just as I hoped. Thank you!!!

Let me know if you want to work on any "tweaks" like we talked about later, such as e-mail notifications. I can also see where a GUI interface would be handy for this tool as well, but again these are just "would be nice" suggestions, and as it is right now, what you've already sent me will save me so much time!

Thanks again

chris128
Aug 12th, 2008, 07:16 AM
No problem - like I said, its not finished yet so let me make it a little more reliable and also make it check to see if the user is already part of the specified dist list first before it attempts to add them (this results in a rather unhelpful error if you do it at the moment).

Are there any other things you want it to do?

Oh and by the way, it will work with normal security groups as well as distribution lists... just thought I'd mention that in case you find that useful as well.

Chris

joechurch
Aug 12th, 2008, 07:21 AM
One quick question, are the admin credentials at the end necessary, or can you simply omit them? I am just curious if you logon as an admin account to the machine you are running this on, if your program will work using the existing credentials of the logged on user.

joechurch
Aug 12th, 2008, 07:21 AM
Yes working with security groups is also helpful, thank you again!

chris128
Aug 12th, 2008, 07:31 AM
At the moment you cant omit the admin credentials, any less than 5 arguments and it wont run. I'll change it tonight though.

chris128
Aug 12th, 2008, 12:51 PM
OK the admin credentials are now optional arguments :)
Current vb project files can be found attached to this post.

joechurch
Aug 12th, 2008, 01:11 PM
OK thanks, I'll try it out. Also FYI - I was able to use a tool called Automate from www.networkautomation.com to built a managed task with an interactive process to get the username, and DLs. This let me build a nice task that I can add e-mail notification and other advanced options that make this a very robust solution.

I'll let you know regarding feedback on the updated files you just posted.

Thanks
Joe

chris128
Aug 12th, 2008, 01:21 PM
Cool :) Not seen that website before but it looks like it might come in handy in the future ;)

joechurch
Aug 12th, 2008, 01:50 PM
Quick question. I am having difficulties with automating the process now for some reason. I am basically repeatedly executing your program multiple times each time with a different DL (for users who want to be removed from more than one). It seems that when I execute the program the first time, it works, and removes the user from the first DL, but then the subsequent runs of your program do nothing. Even though I'm using this automate program, its basically the same as if I had a batch file setup with the proper syntax running your program multiple times with a different DL on each line. Whats happening is that the first time it runs it works and removes from the DL. But then any subsequent times it runs, it does nothing.

Is there any kind of timeout, or anything you can think of that would make running the program multiple times quickly in a row cause any kind of weird issue like this?

joechurch
Aug 12th, 2008, 01:54 PM
I also wanted to ask if you could built in any kind of support for entering multiple DLs during a single execution of your program. I don't know if this is even possible, but I was thinking rather than having to run muiltiple instances of your program back to back to deal with multiple DL removal and addition, would it be possible to setup your program to accept the DLs in a delimited format and act on them all at once at a progarm level? Kind of make the changes all at once rather than once at a time?

I assume an input syntax of something like:

dlmanage remove username "SAMPLE-DL-NAME-1;SAMPLE-DL-NAME-2;SAMPLE-DL-NAME-3"

would something like that be possible?

Thanks
Joe

joechurch
Aug 12th, 2008, 02:10 PM
It seems that if I run the program from a batch file through DOS it works just fine, so it does appear to be a problem running the task from my automate program. I can work on that later, but its not that big a deal as I can still batch and automate the process through DOS and the windows task scheduler as I initially hoped anyway...

joechurch
Aug 12th, 2008, 02:21 PM
Ok I worked out the problem in my automation tool, it works very well now.

I don't really think anything else needs to be added to it, since your program bundled with a batch process or automation tool can accomplish so much as it is now.

You probably don't realize how much time you have just saved me by creating this application. Many thanks!!!

chris128
Aug 13th, 2008, 02:12 AM
Ok I worked out the problem in my automation tool, it works very well now.

I don't really think anything else needs to be added to it, since your program bundled with a batch process or automation tool can accomplish so much as it is now.

You probably don't realize how much time you have just saved me by creating this application. Many thanks!!!
Well, I'm glad you found it useful :)
I could add the function that you mentioned earlier - being able to enter more than one DL at once. Although like you say, this doesnt really acheive much as you can just run the program a few times on a seperate line of the batch file or whatever if you want to do that.
If I do decide to add that 'feature' then would you want it so that if it errored when trying to remove the user from one dist list then it would just exit, or would you want it to carry on and try the other dist lists that were entered in the same command? I'm assuming the latter but just thought I'd check.

Cheers

joechurch
Aug 13th, 2008, 06:43 AM
yeah if it were to be added, I'd say it should keep working and somehow log the error showing the failed DL.

Thanks again!

chris128
Aug 13th, 2008, 07:15 AM
I was thinking about that... like having it output all of the messages to a log file as well as the console screen - because when its running at midnight or whatever there wont be anyone around to see the console screen. I'll see what I can do!

chris128
Aug 13th, 2008, 06:56 PM
OK I've made it log pretty much everything it does now and added the ability to enter more than one dist list by using a comma to seperate them (with no spaces). So an example now would be:

dlmanage.exe add jsmith "All Staff",testdistlist,myotherlist,"New Employees"

You should see a file created in the same location as the exe and config file once you have run the program once, this will be named DL-Log.txt and it should have an up to date log of what the program has done each time you run it :)

Updated project files attached

joechurch
Aug 13th, 2008, 07:24 PM
Awesome, I'll test the new version out tomorrow. Thanks again, this sounds great!

chris128
Aug 14th, 2008, 02:41 PM
Alright cool, let me know if its working fine for you. I've stuck it on my website as you seem to think other people might find it useful. So if you want to get anyone else to download it, they can just go here: http://www.cjwdev.co.uk/programs.html

(yeah I know the website isnt that great but its a work in progress and the best I can do for free!)

bedreaded
Apr 6th, 2009, 12:56 PM
Thanks Chris! This is awesome and much appreciated!:thumb::thumb::D

chris128
Apr 6th, 2009, 01:25 PM
No problem, glad it was of use :)