- How to add holidays to the Exchange calendar with PowerShell - Wed, Apr 23 2014
- How to change the domain name in Exchange Server 2010 - Tue, Apr 8 2014
- How to enable Unsolicited Remote Assistance in Windows 7 / 8 - Tue, Oct 1 2013
If you didn’t know this Outlook feature, you’ll find it in File > Options > Calendar > Add Holidays. Although this is a nice feature, most users probably don’t know it exists, let alone use it. It is possible that your organization might want these holidays to be automatically added to each user’s calendar without any intervention from users themselves.
We’ll start by creating a template Exchange mailbox. In my example, I just used my “helpdesk” mailbox, as the calendar is empty in it.
Once you have a mailbox to use as your template, open it in Microsoft Outlook. We will then import the holidays using the “Add Holidays” feature of Outlook (File > Options > Calendar > Add Holidays). Once the holidays have been added to the calendar, review and amend as required. (I had to remove a few that didn’t apply to us.) The search feature works well here, as the holidays go quite far into the future!
We can check with the Exchange PowerShell Console to see if the number of items seems correct, using the following command:
Get-MailboxFolderStatistics MAILBOXNAME | Select Name, ItemsInFolder
So, in my case, we’re going to be adding 112 calendar entries to everyone’s calendars, as shown in the following screenshot:
If you’re happy with this, the next stage is to export the calendar items to a .PST file. By default, Microsoft Exchange does not grant anyone export/import rights to mailboxes—not even administrators! So we’ll have to grant ourselves permission to do this first.
We can grant the right to an individual user, such as “geoff,” with the following cmdlet:
New-ManagementRoleAssignment –Role “Mailbox Import Export” –User geoff
However, I always prefer to grant the right to an Active Directory security group. For example:
New-ManagementRoleAssignment –Role “Mailbox Import Export” –SecurityGroup Exchange-ImportExport
Now that we’ve got rights to export the calendar to the .PST file, we can do so as follows:
New-MailboxExportRequest –Mailbox MAILBOXNAME –FilePath \\SV02\PST\hol.pst -IncludeFolders “#Calendar#”
This command doesn’t perform the export but creates an export request with Exchange. We can observe the export list and progress with the following command:
After a moment or two, you’ll see that the request has completed, and you should see a .PST file in the location specified in the New-MailboxExportRequest command.
At this stage, we’re ready to import the calendar into other Exchange mailboxes. Before we go crazy on all of our users, it’s probably advisable to test on just one first. Let’s import the calendar entries into Bob’s calendar. Do so as follows:
New-MailboxImportRequest –Mailbox bob –FilePath \\SV02\PST\hol.pst -IncludeFolders “#Calendar#”
If you decide to build this into the scripts/process you run for setting up new users, this will be the command you need for the new accounts. As before, this isn’t imported instantly; rather, it is added to an import queue. You can watch the status with the following command:
Once we’re happy with the result, we can proceed to import to all of our users with a PowerShell command that loops though all of our mailboxes and creates an import request for each:
$users = Get-Mailbox –ResultSize Unlimited
ForEach ($u in $users)
New-MailboxImportRequest –Mailbox $u –FilePath \\SV02\PST\hol.pst -IncludeFolders “#Calendar#”
This part will take quite a while to complete, but you can watch the mailbox import requests with the command we used earlier.
Once all import requests have completed, all users will have your predefined holidays in their calendars.
It’s also worth noting that the steps above can apply to anything that you might find in an Exchange mailbox, and the calendar entries don’t have to only be holidays. You can get quite creative with it!