首页 > 解决方案 > 使用 Powershell 不在默认日历上创建 Outlook 日历

问题描述

我有一个简单的脚本,它将创建一个 Outlook 日历项目(在线找到),它会很好地创建一个日历项目,但它会将它放在我的默认日历上。我怎样才能让它放在特定的日历上?这就是我所拥有的。

$outlook = new-object -com outlook.application
    $CalItem = "1"
    $newAppt = $outlook.CreateItem($CalItem)
    $newAppt.Body = "Test Body222"
    $newAppt.Subject = "Test Subject222"
    $newAppt.Start = $OutObject.StartDate
    $newAppt.End = $OutObject.ImpEndDate
    $newAppt.BusyStatus = 0
    $newAppt.Save()

标签: powershelloutlook

解决方案


我能够做到这一点

# Instantiate a new Outlook object
$ol = new-object -ComObject "Outlook.Application"
# Map to the MAPI namespace
$MyNameSpace = $ol.getnamespace("mapi")
#Default Calendar Folder
$MyDefCal = $MyNameSpace.GetDefaultFolder("olFolderCalendar")
#Folder or "Calendar" I want to add the Item to
$MySharedCal = $MyDefCal.Folders.Item("TestCal") 

#Create the Calendar Item
$MyItem = $MySharedCal.Items.Add(1)
$MyItem.Body = "Test"
$MyItem.Subject = "This Is A Test"
$MyItem.Start = "03/01/2019"
$MyItem.AllDayEvent = 1
$MyItem.ReminderSet = 0
$MyItem.BusyStatus = 0
$MyItem.Save()

感谢 Dimitry 的帮助。


推荐阅读