- 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:
Get-MailboxFolderStatistics
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:
Get-MailboxExportRequest
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:
Get-MailboxImportRequest
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!
Could this or is there a better method be used to frequently copy items from users calendar to a central calendar (think vacation calendar). To automate this, so the users don’t have to enter (drag/drop) items in two calendars.
I have a question, I have many different Windows 7 users connecting thru a VPN using Juniper Network Connect, is there a way to apply policy changes to all the users upon connecting? It’s acceptable if the connecting user must grant permission via security prompt.
Hi Geoff
Long time no speak since our days at Bentleys/Italik. Just looking at this for our organisation and just wondered if if you had problems with delegate permissions being reset on Calendars after doing an global import? Hope all is well mate. Cheers Simon
We used this method and had room calendar permissions set to default, shared calendars lost reviewer permissions, and delegates were all removed from individual calendars. This is a small disaster.
The same happened to me, stupid of me to test and use me or another IT person as a test.. should have tested outside my bubble. All permissions stripped the past apts on the helpdesk calendar all showed up with invites that had to be dismissed for all 800+ users. All permissions were removed for shared users and had to be scripted or granted access all over again, augh. Today I found that the permissions for the Calendar that I had on the calendar overwrote everyone else’s. So by default we only saw free or busy on everyone’s calendar unless granted more access, well now everyone can see everyone’s information across the board. Nothing like making a leap of faith and falling face first. Lesson learned here. Test environment goes up soon.
This is great! Exactly what I was looking for.
Can you import to members of a distribution group? As oppose to every exchange mailbox.
Thanks!
New-MailboxExportRequest : The term ‘New-MailboxExportRequest’ is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
Get-MailboxExportRequest : The term ‘Get-MailboxExportRequest’ is not recognized as the name of a cmdlet, function,
script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
This cmdlet is available only in on-premises Exchange
This was amazing.
For anyone struggling with this, you need to run these commands in "Exchange shell" on your Exchange server. Alternatively, you can link your Powershell session with Exchange shell via:
$ExchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://[FQDN of your server]/PowerShell/
Import-PSSession $ExchangeSession
For those looking for a way to do this in exchange online / office 365:
– Create the pst in a local outlook client (we created a temp mailbox for this)
– Use Network upload to import your pst to Microsoft 365 (you can find a step by step from microsoft to do this here: https://learn.microsoft.com/en-us/microsoft-365/compliance/use-network-upload-to-import-pst-files?view=o365-worldwide)
Good luck!