自动将ICS文件导入outlook.com

时间:2015-12-11 17:34:55

标签: calendar outlook.com

我有* .ics文件,想要将其导入outlook.com上的日历。如何使用PowerShell脚本执行此操作?

我需要删除并重新创建我导入的日历,或者在导入之前清除日历。

提前致谢。

1 个答案:

答案 0 :(得分:0)

尝试

步骤1:阅读ics文件的内容

第2步:解析

步骤3:在Powershell中使用Outlook应用程序对象

第4步:获取日历文件夹

步骤5:使用日历文件夹的属性在步骤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."}
}

确认&#34; thescriptkeeper.wordpress.com&#34;对于剧本