2017-01-05 38 views
-1

我在下面的PowerShell中工作得很好,直到去年11月份的第一次。powershell https://outlook.office365.com/api/v1.0/me/messages

$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 

我得到下面的错误: 调用-RestMethod:远程服务器返回错误:(400)错误的请求。 在G:\ Powell \ AutoetForO.ps1:23 char:13 + $ messages = Invoke-RestMethod $ messageQuery -Credential $ cred + ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~类别信息: ,WebException + FullyQualifiedErrorId:WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

根据我的调查;我知道它不是凭证问题;我认为他们改变了他们的API。

+0

我在那里看不到问题。 –

+0

问题是:“我怎样才能使它工作?”。它一直工作到11月1日。这个错误根本没有帮助;我知道它不是凭据相关的。 – Chicago1988

回答

0

运行使用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"