« Great scripting site: Glen Scales | Main | Exchange and Outlook build info »
October 07, 2004
So many ways to script!
One of the problems with writing scripts for Exchange is the sheer amount of information you need to have at least passing familiarity with. Not only do you need to get a pretty good grasp of Exchange internals, but you also have to be able to use VBScript (you can use other languages, but since we're using VBscript for the majority of our scripts, that's what I'm assuming here) to interface with the following technologies:
One of the problems with writing scripts for Exchange is the sheer amount of information you need to have at least passing familiarity with. Not only do you need to get a pretty good grasp of Exchange internals, but you also have to be able to use VBScript (you can use other languages, but since we're using VBscript for the majority of our scripts, that's what I'm assuming here) to interface with the following technologies:
WSH
The Windows Scripting Host doesn't directly provide a lot of the functionality that serious scripts need, but it is a vital part of writing VBScript and JScript administrative scripts. It basically provides the glue for scripts to make use of other technologies and can be thought of as the environment that is provided while a script is running. It provides the native ability for simple tasks like managing network and printer connections, allows the use of any COM objects that support Automation, provides standard programming features such as input/output and registry manipulation, and the ability to run command-line tools.
The Script Runtime library
The Script Runtime library provides a collection of objects so that VBScript can perform additional tasks such as directly manipulating the filesystem and using simple data structures called dictionaries.
Active Directory Service Interfaces (ADSI)
ADSI is a collection of interfaces that allow you to perform all the required directory management functions. It's simple to learn, but to get the most out of it, you have to be willing to dive into the Active Directory schema and learn the objects and properties it contains. ADSI allows you to connect to multiple directories: Active Directory, third-party LDAP directories, SAM databases for both local machines and Windows domains, IIS metabases, and other directories given the appropriate provider binaries.
Windows Management Instrumentation (WMI)
WMI is a comprehensive way to collect and modify management information across the enterprise. It provides a large number of objects that allow you to manage Windows 2000/XP/2003 machines (and even a limited set of functionality on NT 4 machines with the correct add-on), network services, .NET applications, monitoring, and more.
Collaboration Data Objects (CDO)
CDO provides a client-side interface for manipulating mailboxes and message objects. There have been several different flavors that provide different capabilities depending on the underlying operating system and transport.
Collaboration Data Objects for Exchange Management (CDOEXM)
CDOEXM provides access to Exchange server-side management tasks, much like CDO grants access to the Outlook client-side tasks.
As can be expected, there are sometimes many overlaps between these technologies; a given task can usually be accomplished in many ways. Writing manageable, successful scripts requires the use of all of these methods. However, there are still some tasks that just don't seem possible, or seem horribly complicated from the scripter standpoint.
One solution to this problem is to switch from a scripted language to compiled code like Visual Basic or Visual C++. These grant you access to the full range of programming interfaces, not just those with Automation interfaces. While they introduce a bit more overhead into the development process, by the time you get to the point where you need to go this point, you've probably put a significant amount of time and effort into your scripting infrastructure to begin with; switching to compiled code can help you clean up and unify these scripts.
Another interesting solution, suitable especially to problems that CDO and CDOEXM seems like they should be able to help you with but can't, is the use of the Exchange OWA interface. As OWA can't use the full programmatic MAPI libraries, this interface builds on the WebDAV interface to provide a deep amount of flexibility and functionality. Scripting to the OWA interface can often be the simplest way to solve a given problem, so don't forget to include it in your toolbox.
Glen's Exchange Dev Blog, written by Glen Scales, provides a treasure trove of advanced Exchange scripting tasks. It also provides a useful look at how to make use of the OWA interface for many tasks. I know Paul has already linked to this blog once, but it's definitely a blog to keep bookmarked.
Posted by Devin Ganger at October 7, 2004 03:08 AM