2016-04-28 66 views
0

我想使用PowerShell來查詢組日曆,並根據主題字段中的特定字符串返回僅一部分事件。PowerShell - Office365日曆REST API v1.0:按主題搜索

目前,我可以使用下面的和得到的所有事件的列表:

$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 

這是我卡住。我試圖篩選這些結果的地方,我只返回結果,其中Subject -like '*string*'

不過,我只是似乎無法得到這對Invoke-RestMethod線工作...

任何幫助將不勝appreaciated。

獎金欣賞的人誰可以採取的開始和結束時間的結果,從這樣的:

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.

回答

0

因爲你使用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 

與開始停止的時間只投其中例如

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

歡呼聲 格倫

+0

史詩先生。謝謝! – zackm