0

I have an *.ics file and want to import it to my calendar on outlook.com. How can I do this with a powershell script?

I need to either delete and recreate the calendar I import to, or clear the calendar before import.

Thanks in advance.

Generic Name
  • 1,083
  • 1
  • 12
  • 19
  • Can you post the code you tried till now – srg Dec 11 '15 at 17:58
  • I haven't tried anything yet. I don't know where to start. I have an *.ics file and I can import it by clicking 'import' on outlook.com, but I don't know how to do this via a script. – Generic Name Dec 12 '15 at 12:50

1 Answers1

0

Try

Step 1: Read the contents of the ics file

Step 2: Parse it

Step 3: Use Outlook Application Object in Powershell

Step 4: Get the Calendar folder

Step 5: use the properties of the calendar folder to add the parsed content in step 2

#Folder containing ICS files

$ICSpath="C:\Users\test\testasdasd"
$ICSlist = get-childitem $ICSPath

Foreach ($i in $ICSlist )
{
     $file= $i. fullname
     $data = @{}
     $content = Get-Content $file -Encoding UTF8
     $content |
     foreach-Object {
      if($_.Contains(':')){
            $z=@{ $_.split( ':')[0] =( $_.split( ':')[1]).Trim()}
           $data. Add( $z. Keys, $z. Values)
       }
     }
     $outlook = new-object -com Outlook.Application
    $calendar = $outlook.Session.GetDefaultFolder(9) 
    $appt = $calendar.Items.Add(1)


     $Body=[regex]::match($content,'(?<=\DESCRIPTION:).+(?=\DTEND:)', "singleline").value .trim ()
     $Body= $Body -replace "\r\n\s"
     $Body = $Body.replace("\,",",").replace("\n"," ")
     $Body= $Body -replace "\s\s"

     $Start = ($data.getEnumerator() | ?{ $_.Name -eq "DTSTART"}).Value -replace "T"
     $Start = [datetime]::ParseExact ($Start ,"yyyyMMddHHmmss" ,$null )

     $End = ($data.getEnumerator() | ?{ $_.Name -eq "DTEND"}).Value -replace "T"
     $End = [datetime]::ParseExact ($End ,"yyyyMMddHHmmss" ,$null )

     $Subject = ($data.getEnumerator() | ?{ $_.Name -eq "SUMMARY"}).Value
     $Location = ($data.getEnumerator() | ?{ $_.Name -eq "LOCATION"}).Value

     $appt.Start = $Start
     $appt.End = $End
     $appt.Subject = $Subject
     $appt.Categories = "Presentations" #Pick your own category!
     $appt.BusyStatus = 0   # 0=Free
     $appt.Location = $Location
     $appt.Body = $Body
     $appt.ReminderMinutesBeforeStart = 15 #Customize if you want 

     $appt.Save()
    if ($appt.Saved)
        { write-host "Appointment saved."}
    Else {write-host "Appointment NOT saved."}
}

Acknowledging "thescriptkeeper.wordpress.com" for the script

srg
  • 265
  • 2
  • 8
  • Ok. But I want to write it to the web app Outlook.com and not the desktop application Outlook :-). I don't have Outlook installed on the machine in question. – Generic Name Dec 14 '15 at 15:02