Enterprise Powershell: Creating Mail-Enabled Contacts in Exchange 2003
Finally, the big moment arrives; you are now invoking the "MailEnable" member of the CDOEXM assembly. The five-parameter call to invokemember is simple and powerful. Against the assembly you are calling "MailEnable", with the binding flags declared earlier in the script, a null reference to the binder that results in this invocation using the default binding, the native object to which "MailEnable" is being applied, and lastly any arguments that are used during the invocation. Once this step is completed, you modify the user's directory entry by updating the 'altrecipient' and 'forwardingaddress' properties. Finally, upon committing the changes, you'll have a user whose mail will be forwarded according to the mail-enabled contact.
# call the assembly which takes the native object and performs # MailEnable and commit the change $Assembly_Type.invokemember("MailEnable",$Binding_Flags,$null, $Contact.psbase.nativeobject, "SMTP:$email") $Contact.psbase.CommitChanges() # set the contact as the mail forward $Person.psbase.invokeset("altrecipient", $Contact.psbase.invokeget('distinguishedName')) $Person.psbase.invokeset("forwardingaddress", $Contact.psbase.invokeget('distinguishedName')) $Person.psbase.CommitChanges() #output a message stating what has been done Write-Host "Email for $Account will be forwarded to $email" #close connections $Domain_Searcher.dispose | out-null $Forward_Container.dispose | out-null
Running this script will produce the following output on the Powershell console, as shown in Figure 1.
Figure 1: Output on the Powershell console
As your Exchange messaging environment grows and through the course of time, you'll no doubt be asked to diversify mail settings for your current users or ones who no longer have accounts. In either case, this article goes to show how you can use Powershell to interface with some of the more advanced concepts of scripting your Exchange 2003 environment. If you build further on what is presented here, let the author know by emailing him at jonATshobergDOTnet.
About the Author
Jon Shoberg is a developer for The Ohio State University. He has extensive experience in developing enterprise systems in e-commerce, web, and search domains on the LAMP, Java, and .NET platforms. Jon has previously contributed to books and industry publications as a technical reviewer and coauthor, respectively.
Page 2 of 2