Categories
Sponsors
Archive
![](/wp-content/themes/metro/images/tag.gif) Blogroll
Badges
Community
|
How to sync Outlook Calendars between Exchange accounts with PowerShell?
Posted in Windows Powershell | 3 Comments | 7,733 views | 16/01/2012 23:43
I wrote a calendar sync script for Outlook to sync calendars between Exchange accounts. If you need to sync your calendars, accounts should be in same Outlook profile. I didn’t figure out how to sync between different profiles yet, but will work on it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| Function Sync-OutlookCalendar
{
# Connect to Outlook
$Outlook = New-Object -com Outlook.Application
# Get Calendars
$Calendar1 = $Outlook.Session.folders.Item(1).Folders | where {$_.DefaultMessageClass -eq "IPM.Appointment"}
$Calendar2 = $Outlook.Session.folders.Item(2).Folders | where {$_.DefaultMessageClass -eq "IPM.Appointment"}
# Search Calendar Items
$Calendar1Items = $Calendar1.items | Where {$_.Start -gt (Get-Date)} | Select-Object -Property Start, End, Subject, Location, MeetingStatus
# Sync All: $Calendar1Items = $Calendar1.items | Select-Object -Property Start, End, Subject, Location, MeetingStatus
# Sync Calendar Items
Foreach ($Calendar1Item in $Calendar1Items)
{
$SearchDuplicate = $Calendar2.items | Where {$_.Start -eq $Calendar1Item.Start -and $_.End -eq $Calendar1Item.End -and $_.Subject -eq $Calendar1Item.Subject} | Select-Object -Property Start, End, Subject, Location, MeetingStatus
if ($SearchDuplicate -eq $null)
{
$Appointment = $Calendar2.Items.Add(1)
$Appointment.Start = $Calendar1Item.Start
$Appointment.End = $Calendar1Item.End
$Appointment.Subject = $Calendar1Item.Subject
$Appointment.Location = $Calendar1Item.Location
$Appointment.MeetingStatus = $Calendar1Item.MeetingStatus
$Appointment.Save()
}
else
{
Write-Host "Appointment is already exist"
}
}
} |
Function Sync-OutlookCalendar
{
# Connect to Outlook
$Outlook = New-Object -com Outlook.Application
# Get Calendars
$Calendar1 = $Outlook.Session.folders.Item(1).Folders | where {$_.DefaultMessageClass -eq "IPM.Appointment"}
$Calendar2 = $Outlook.Session.folders.Item(2).Folders | where {$_.DefaultMessageClass -eq "IPM.Appointment"}
# Search Calendar Items
$Calendar1Items = $Calendar1.items | Where {$_.Start -gt (Get-Date)} | Select-Object -Property Start, End, Subject, Location, MeetingStatus
# Sync All: $Calendar1Items = $Calendar1.items | Select-Object -Property Start, End, Subject, Location, MeetingStatus
# Sync Calendar Items
Foreach ($Calendar1Item in $Calendar1Items)
{
$SearchDuplicate = $Calendar2.items | Where {$_.Start -eq $Calendar1Item.Start -and $_.End -eq $Calendar1Item.End -and $_.Subject -eq $Calendar1Item.Subject} | Select-Object -Property Start, End, Subject, Location, MeetingStatus
if ($SearchDuplicate -eq $null)
{
$Appointment = $Calendar2.Items.Add(1)
$Appointment.Start = $Calendar1Item.Start
$Appointment.End = $Calendar1Item.End
$Appointment.Subject = $Calendar1Item.Subject
$Appointment.Location = $Calendar1Item.Location
$Appointment.MeetingStatus = $Calendar1Item.MeetingStatus
$Appointment.Save()
}
else
{
Write-Host "Appointment is already exist"
}
}
}
Every time you execute the script, it checks the duplicate entries. So you can’t sync if same appointment is also exist on other calendar. Also I thought to sync only new appointments, so there is a date checker too. You can change it if you want to sync all time appointments.
Comments (3)
Leave a Reply
|