gpt4 book ai didi

powershell - 使用 powershell : Unwanted results 从 Outlook 获取今天的约会

转载 作者:行者123 更新时间:2023-12-02 22:56:55 33 4
gpt4 key购买 nike

我正在使用以下代码提取今天的约会:

$olFolderCalendar = 9
$ol = New-Object -ComObject Outlook.Application
$ns = $ol.GetNamespace('MAPI')
$Start = (Get-Date).AddDays(-1).ToShortDateString() + " 00:00"
$End = (Get-Date).AddDays(+1).ToShortDateString() + " 00:00"

$Filter = "[MessageClass]='IPM.Appointment' AND [Start] > '$Start' AND [End] < '$End'"

$Appointments = $ns.GetDefaultFolder($olFolderCalendar).Items
$Appointments.Sort("[Start]")
$Appointments.IncludeRecurrences = $false

foreach ($Appointment in $Appointments.Restrict($Filter) ) {
...
}

列出了所有今天的约会,但也列出了许多今天没有发生的重复约会(生日、每周约会……)。知道如何避免这种情况吗?

编辑:似乎所有这些不需要的约会最初都是从我的手机同步到 Outlook 的。我将在“干净”的 PC 上尝试该脚本。

编辑:我在另一台没有同步元素的 PC 上尝试了该脚本,结果是一样的:所有重复出现的元素都会显示,无论它们是否在今天。
AND [IsRecurring] = '$False'
也没有帮助。

最佳答案

初始查询必须包含该系列的原始约会,因此如果该系列在 3 个月前开始,则必须相应设置约会集合 ($folder.items) 日期范围。

之后,您可以筛选所需的日期范围。

此代码有效:

Function Get-OutlookCalendar
{
echo starting...
Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$folder = $namespace.getDefaultFolder($olFolders::olFolderCalendar)

$a = Get-Date -Hour 0 -Minute 00 -Second 00
$b = (Get-Date -Hour 0 -Minute 00 -Second 00).AddDays(7)
echo From $a To $b

$Appointments = $folder.Items
$Appointments.IncludeRecurrences = $true
$Appointments.Sort("[Start]")

$Appointments | Where-object { $_.start -gt $a -AND $_.start -lt $b } | Select-Object -Property IsRecurring, RecurrenceState, Subject, Start, Location

} #end function Get-OutlookCalendar

运行这个 - 对于傻瓜,就像我昨天一样:)
cmd
powershell
PS C:\Users\Jose\Documents\WindowsPowerShell> Import-Module -Name Outlook\expcal.psm1 -Force
PS C:\Users\Jose\Documents\WindowsPowerShell> Get-OutlookCalendar

关于powershell - 使用 powershell : Unwanted results 从 Outlook 获取今天的约会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9892352/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com