Reputation: 371
I'm trying to retrieve Google Calendar events and bulk-copy them into a SQL Server table.
$requestUri = "https://www.googleapis.com/calendar/v3/calendars/.../events"
$calEvents = Invoke-RestMethod -Headers @{Authorization = "Bearer $accessToken"} -Uri $requestUri -Method Get -Body $Parameters -ContentType "application/json; charset=utf-8"
$dt = $calEvents.items | Select-Object id, ????????? | Out-DataTable
...
$bulkCopy.WriteToServer($dt)
So my question is what to put into ????? so I would be able to save for organizer-email, creator-email, start-date, end-date into the table.
$calEvents.items
looks like this:
created : 2017-08-28T07:18:19.000Z updated : 2017-08-29T16:41:00.441Z summary : Vacation creator : @{[email protected]; displayName=XXX} organizer : @{[email protected]} start : @{date=2018-03-26} end : @{date=2018-03-31} ...
So I want to retrieve only email and date elements from @{}
multivalues.
Any idea how?
(I know I can expand only one property).
Upvotes: 2
Views: 4483
Reputation: 17492
other method:
$dt = $calEvents.items | %{
[pscustomobject]@{
id=$_.id
organizer=$_.organizer.email
start=$_.start.date
end=$_.end.date
}
} | Out-DataTable
Upvotes: 0
Reputation: 200493
Those are most likely nested objects. You should be able to "flatten" your data by using calculated properties:
$dt = $calEvents.items |
Select-Object id, @{n='creator';e={$_.creator.email}},
@{n='organizer';e={$_.organizer.email}},
@{n='start';e={$_.start.date}},
@{n='end';e={$_.end.date}} |
Out-DataTable
Upvotes: 4