powershell https://outlook.office365.com/api/v1.0/me/messages
powershell https://outlook.office365.com/api/v1.0/me/messages
直到去年 11 月 1 日,我才让下面的 Powershell 完美运行。
$url = "https://outlook.office365.com/api/v1.0/me/messages"
$date = Get-Date -Format "yyyy-MM-d"
## Get all messages that have attachments where received date is greater than $date
$messageQuery = "" + $url + "?`$select=Id&`$filter=HasAttachments eq true and DateTimeReceived ge " + $date
$messages = Invoke-RestMethod $messageQuery -Credential $cred
我收到以下错误:
Invoke-RestMethod:远程服务器返回错误:(400)错误请求。
在 G:\Powell\AutoetForO.ps1:23 char:13
+ $messages = 调用-RestMethod $messageQuery -Credential $cred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo:InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest)[Invoke-RestMethod],WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
根据我的调查;我知道这不是凭证问题;我认为他们改变了 API.
运行 使用 Fiddler 捕获流量的相同脚本我发现错误响应的正文是:
92
{"error":{"code":"RequestBroker-ParseUri","message":"Syntax error at position 54 in 'HasAttachments eq true and DateTimeReceived ge 2017-01-5'."}}
0
日期看起来像是问题所在。将第二行更改为以下内容可解决问题:
$date = Get-Date -Format "yyyy-MM-dd"
直到去年 11 月 1 日,我才让下面的 Powershell 完美运行。
$url = "https://outlook.office365.com/api/v1.0/me/messages"
$date = Get-Date -Format "yyyy-MM-d"
## Get all messages that have attachments where received date is greater than $date
$messageQuery = "" + $url + "?`$select=Id&`$filter=HasAttachments eq true and DateTimeReceived ge " + $date
$messages = Invoke-RestMethod $messageQuery -Credential $cred
我收到以下错误: Invoke-RestMethod:远程服务器返回错误:(400)错误请求。 在 G:\Powell\AutoetForO.ps1:23 char:13 + $messages = 调用-RestMethod $messageQuery -Credential $cred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo:InvalidOperation:(System.Net.HttpWebRequest:HttpWebRequest)[Invoke-RestMethod],WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
根据我的调查;我知道这不是凭证问题;我认为他们改变了 API.
运行 使用 Fiddler 捕获流量的相同脚本我发现错误响应的正文是:
92
{"error":{"code":"RequestBroker-ParseUri","message":"Syntax error at position 54 in 'HasAttachments eq true and DateTimeReceived ge 2017-01-5'."}}
0
日期看起来像是问题所在。将第二行更改为以下内容可解决问题:
$date = Get-Date -Format "yyyy-MM-dd"