Connect Workday to your favorite reporting tools without moving data.
Learn More →Automate Google Calendar Integration Tasks from PowerShell
Are you looking for a quick and easy way to access Google Calendar data from PowerShell? We show how to use the Cmdlets for Google Calendar and the CData ADO.NET Provider for Google Calendar to connect to Google Calendar data and synchronize, automate, download, and more.
The CData Cmdlets for Google Calendar are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time and bidirectional access to Google Calendar.
Cmdlets or ADO.NET?
The cmdlets are not only a PowerShell interface to the Google Calendar API, but also an SQL interface; this tutorial shows how to use both to create, retrieve, update, and delete Google Calendar data. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Google Calendar. To access Google Calendar data from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Google Calendar.
After obtaining the needed connection properties, accessing Google Calendar data in PowerShell consists of three basic steps.
You can connect to Google APIs on behalf of individual users or on behalf of a domain. Google uses the OAuth authentication standard. See the "Getting Started" section of the help documentation for a guide.
PowerShell
-
Install the module:
Install-Module GoogleCalendarCmdlets
-
Connect:
$googlecalendar = Connect-GoogleCalendar
-
Search for and retrieve data:
$searchterms = "beach trip" $vacationcalendar = Select-GoogleCalendar -Connection $googlecalendar -Table "VacationCalendar" -Where "SearchTerms = `'$SearchTerms`'" $vacationcalendar
You can also use the Invoke-GoogleCalendar cmdlet to execute SQL commands:
$vacationcalendar = Invoke-GoogleCalendar -Connection $googlecalendar -Query 'SELECT * FROM VacationCalendar WHERE SearchTerms = @SearchTerms' -Params @{'@SearchTerms'='beach trip'}
ADO.NET
-
Load the provider's assembly:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Google Calendar\lib\System.Data.CData.GoogleCalendar.dll")
-
Connect to Google Calendar:
$conn= New-Object System.Data.CData.GoogleCalendar.GoogleCalendarConnection("InitiateOAuth=GETANDREFRESH") $conn.Open()
-
Instantiate the GoogleCalendarDataAdapter, execute an SQL query, and output the results:
$sql="SELECT Summary, StartDateTime from VacationCalendar" $da= New-Object System.Data.CData.GoogleCalendar.GoogleCalendarDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.summary $_.startdatetime }
Update Google Calendar Data
PowerShell
Update-GoogleCalendar -Connection $GoogleCalendar -Columns @('Summary','StartDateTime') -Values @('MySummary', 'MyStartDateTime') -Table VacationCalendar -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.GoogleCalendar.GoogleCalendarCommand("UPDATE VacationCalendar SET SearchTerms='beach trip' WHERE Id = @myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.GoogleCalendar.GoogleCalendarParameter("@myId","10456255-0015501366"))
$cmd.ExecuteNonQuery()
Insert Google Calendar Data
PowerShell
Add-GoogleCalendar -Connection $GoogleCalendar -Table VacationCalendar -Columns @("Summary", "StartDateTime") -Values @("MySummary", "MyStartDateTime")
ADO.NET
$cmd = New-Object System.Data.CData.GoogleCalendar.GoogleCalendarCommand("INSERT INTO VacationCalendar (SearchTerms) VALUES (@mySearchTerms)", $conn)
$cmd.Parameters.Add(new System.Data.CData.GoogleCalendar.GoogleCalendarParameter("@mySearchTerms","beach trip"))
$cmd.ExecuteNonQuery()
Delete Google Calendar Data
PowerShell
Remove-GoogleCalendar -Connection $GoogleCalendar -Table "VacationCalendar" -Id "MyId"
ADO.NET
$cmd = New-Object System.Data.CData.GoogleCalendar.GoogleCalendarCommand("DELETE FROM VacationCalendar WHERE Id=@myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.GoogleCalendar.GoogleCalendarParameter("@myId","001d000000YBRseAAH"))
$cmd.ExecuteNonQuery()
CodeProject