根据屏幕截图,我正在寻找一种从消息中心获取(更新)消息的有效方法。
使用Office365ServiceCommunicationsAPI是直截了当的,但根据文档,我们不能通过LastUpdatedTime过滤或订购。据我所见,检测更新消息的唯一可靠方法是比较StartTime < LastUpdatedTime。
尝试按LastUpdateTime订购会产生预期的错误消息,并与文档匹配。
"message": "The query specified in the URI is not valid. Order by 'LastUpdatedTime' is not allowed. To allow it, set the 'AllowedOrderByProperties' property on EnableQueryAttribute or QueryValidationSettings.",如果不能为$orderby ODATA筛选器设置LastUpdateTime desc,就无法有效地获取更新的消息。它需要加载所有消息并进行客户端过滤。
有数百条消息,而StartTime和LastUpdateTime之间的潜在周期是未知的,所以我甚至不能过滤到一个子集(例如StartTime gt 7 days)。必须始终处理每一条消息,以确保不会错过更新的消息。
我想要收到完全相同的表示和顺序的消息(更新和未更新),在消息中心本身和根据屏幕截图。
我错过了更好的选择吗?

发布于 2020-07-22 06:37:39
由于社区既没有任何答案,也在文档中找不到任何提示,所以我通过观察实现了自己的客户端逻辑。
解决方案
# Get all Messages from Message Center
function Get-ServiceCommMessages {
[CmdletBinding()]
param (
$DaysToSync
)
# Invoke-ServiceCommMethod is just a wrapper function for Invoke-WebRequest and Access Token acquisition.
# https://github.com/sebastianzolg/PSServiceComm
$messages = Invoke-ServiceCommMethod -Method '/ServiceComms/Messages' | Sort-Object LastUpdatedTime -Descending
If($PSBoundParameters.ContainsKey('DaysToSync')){
$messages = $messages | Where-Object LastUpdatedTime -ge (Get-Date).AddDays(-$daysToSync).Date
}
$messages | Add-Member -MemberType ScriptMethod -Name "IsUpdated" -Value {
($this.LastUpdatedTime -ge ($this.StartTime).AddHours(1)) -and ($this.Title -match [Regex]::Escape('(Updated)'))
} -Force
return $messages
}# Get all messages for the last 5 days and filter for updates
$messages = Get-ServiceCommMessages -DaysToSync 5
$messages | Where-Object { $_.IsUpdated() }更新被视为满足以下条件的消息:
Title contains '(Updated)'LastUpdatedTime > StartTime + 1 Hour我已经将逻辑打包到一个非常简单的PowerShell核心模块中,您可以在Github上找到它。
https://stackoverflow.com/questions/62948576
复制相似问题