PowerShell - Office365 Calendar REST API v1.0:按主题搜索

PowerShell - Office365 Calendar REST API v1.0: Search by Subject

我正在尝试使用 PowerShell 查询组日历,并且 return 仅基于主题字段中的特定字符串查询事件的子集。

目前,我可以使用以下方法获取所有事件的列表:

$events = Invoke-RestMethod -Uri "https://outlook.office365.com/api/v1.0/users/$calendar/calendarview?startDateTime=$(Get-Date)&endDateTime=$((Get-Date).AddDays(1))" -Credential $cred | foreach-object{$_.Value}

$events | Select-Object -Property Subject,Start,End | fl

这就是我卡住的地方。我正在尝试将这些结果过滤到 return 结果 Subject -like '*string*'

但是,我似乎无法让它在 Invoke-RestMethod 行上运行...

我们将不胜感激任何帮助。

感谢任何可以从中获取开始和停止时间结果的人:

2016-04-25T13:00:00Z

对此:

4/25/2016

作为参考,我已经试过了:

Get-Date $events.Start -Format 'MM/dd/yyyy'

出现此错误:

Get-Date : Cannot convert 'System.Object[]' to the type 'System.DateTime' required by parameter 'Date'. Specified method is not supported.

因为您使用的是 CalendarView(它是一种过滤器),所以您无法在 REST 级别应用其他过滤器,因此只需过滤结果即可,例如

$events | Where-Object {$_.Subject -match 'string'} | Select-Object -Property Subject,Start,End | fl

或者如果您想使用通配符

$events | Where-Object {$_.Subject -Like '*string*'} | Select-Object -Property Subject,Start,End | fl

随着开始停止时间,只需 CAST 即可,例如

$events | % {([DateTime]$_.Start).ToString("MM/dd/yyyy")}

干杯 格伦