PowerShell: SharePoint 2013 - Add Recurring Events to Calendar Programmatically

Updated on 11/13/2013
$Assem = ( 
"Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
) 
         
$Source = @"
    using System;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Administration;
 
    namespace Test
    {
        public class CodeToRun
        {
            public static void CreateEvents()
            {
                using (SPSite siteCollection = new SPSite("http://sharepoint/"))
                {
                    SPWeb web = siteCollection.RootWeb;
                    SPList list = web.Lists["Calendar"];
                     
                    for(int x=0; x<5; x++)
                        {
						SPListItem recEvent = list.Items.Add();

						string recData = "<recurrence><rule>" + 
						    "<firstDayOfWeek>su</firstDayOfWeek>" +
						    "<repeat><daily dayFrequency='1' /></repeat>" +
						    "<repeatInstances>5</repeatInstances></rule></recurrence>";

                        recEvent["Title"] = "test" + x.ToString();
                        recEvent["RecurrenceData"] = recData;
                        recEvent["EventType"] = 1;
                        recEvent["EventDate"] = new DateTime(2013,5,8,8,0,0);
                        recEvent["EndDate"] = new DateTime(2013,9,8,9,0,0);
                        recEvent["UID"] = System.Guid.NewGuid();
                        recEvent["TimeZone"] = 13;
                        recEvent["Recurrence"] = -1;            
 
                        recEvent.Update();
                    }
                }
            }
        }
    }
"@
 
Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp #-Debug
[Test.CodeToRun]::CreateEvents()