Wednesday, August 3, 2011

Automatically Create Outlook Profile During Logon With A VBScript

The Problem

A common annoyance facing many administrators and helpdesk personnel is the need to configure an Outlook (MAPI) profile for their end-users every time they log on to a new machine for the first time. The issue becomes less predominant when user accounts are configured with roaming profiles, but nonetheless, configuring Outlook settings every time a new user is added to the domain, or after every subsequent profile reset can quickly become an administrative burden. Beginning with Outlook 2007, Microsoft tried to mitigate this problem by attempting to auto-discover the user's mailbox on an Exchange Server in your org, but even clicking "Next" and "Finish" seems to be out of the technical scope of most users, and often warrants a call to the helpdesk. Moreover, you may wish to forego Cached Exchange Mode, which is enabled by default.

The Solution

You can overcome this monotonous waste of time by using a simple VBScript to check the HKCU registry hive for the presence of an end-user's Outlook (MAPI) profile when they log on to a machine. If no profile is found, you can then import a custom .prf file containing all of the necessary configuration settings for your environment.

Choosing A Tool To Generate The .PRF

The tool you choose to configure your custom .prf should depend on the diversity of Outlook clients on your network. If you have the good fortune of consistent refresh cycles, your client PCs may all be running Office 2007 and above, in which case you may use the Office Customization Tool included in the Admin folder on the installation media for all volume-licensed copies of Office 2007/2010. However, if your environment is more typical of many SMEs, you likely have some workstations loaded with Office 2003 or XP, and some with Office 2007 or 2010. If this is the case, you should use the Custom Installation Wizard included with the Resource Kit Tools for Office 2003 or XP, whichever is the lowest active version in your environment. I will gear these instructions towards the ork for 2003, because that seems to be the lowest common denominator in most cases. Note that Outlook is backwards-compatible with .prf files created in all previous versions, dating back to Office XP. Please obtain the appropriate tool from the Microsoft Download Center by choosing from one of the following links:

Creating The Custom .PRF

Once you've downloaded and installed the Office 2003 Resource Kit Tools, locate installation media for Office 2003, because you will need to point to the [OfficeEdition][Version].msi in order to utilize the tool. For example, the installer for Office 2003 Professional is PRO11.msi, and is located in the root folder of the installation media. Perform the following steps to generate your custom .prf file:

  1. Open the Custom Installation Wizard, and point it to the appropriate installer file
  2. Select "Create a new MST file" and then click "Next"
  3. Click the drop-down box in the upper-right corner of the CIW window, and skip to step 17, which is titled "Outlook: Configure Default Profile"
  4. Select the "New Profile" option, and specify the name of the profile to be created (I HIGHLY recommend using the default profile name of "Outlook")
  5. Click "Next"
  6. Click "Configure an Exchange Server connection" (Note: the %UserName% environment variable, which is filled in for the "User Name" field by default, will resolve to the username of the person who logs on and imports this .prf)
  7. Specify the name of your Exchange Server in the "Exchange Server" field (Tip: create an alias (CNAME) record on your DNS server that resolves to Exchange, and specify the alias in this field. If you migrate Exchange in the future, you can simply change the CNAME record to resolve to your new host, keeping the functionality of your import script intact)
  8. Configure the desired settings for Cached Exchange Mode, and then click "Next"
  9. Click "Next" to skip the "Add Accounts" step, unless you wish to configure additional accounts
  10. Click the "Export Profile Settings..." button, and save your custom .prf
  11. Close the Custom Installation Wizard
  12. Open the .prf in a text editor, such as notepad, and review all settings; make changes as required (Note: detailed information regarding these settings can be found here)
  13. Copy your custom .prf to a network location accessible by all applicable users
VBScript To Automatically Import The .PRF

Copy the following VBScript code, paste it into a text editor (such as notepad), and save the file as CreateOutlookProfile.vbs:

Now, edit CreateOutlookProfile.vbs, and fill in the appropriate values for the PRFLocation and ProfileName variables at the top of the script. Set PRFLocation to the UNC path where you copied your custom .prf, and set ProfileName to the profile name that you assigned when generating your .prf. If you followed my recommendation above, the ProfileName should be "Outlook". Be sure to leave the quotation marks around these values, as they must be string literals. Save the changes you've made, and then assign this as a logon script via your preferred method. I suggest either using a GPO, or launching from within another script that you've already deployed.

1 comment:

  1. Should this work with Outlook 2016? I can't seem to get it to bypass the import option once the profile has been imported.

    ReplyDelete