Ready to get started?

Download a free trial of the Google Search Data Provider to get started:

 Download Now

Learn more:

Google Search Icon Google Search ADO.NET Provider

Easy-to-use Google search client enables .NET-based applications to easily search Google and filter search results.

Automate Google Search Integration Tasks from PowerShell



Are you in search of a quick and easy way to access Google Search results from PowerShell? This article demonstrates how to utilize the Google Search Cmdlets for tasks like connecting to Google Search results, automating operations, downloading data, and more.

The CData Cmdlets for Google Search are standard PowerShell cmdlets that make it easy to accomplish data cleansing, normalization, backup, and other integration tasks by enabling real-time access to Google Search.

PowerShell Cmdlets or ADO.NET Provider?

The Cmdlets are not only a PowerShell interface to Google Search, but also an SQL interface; this tutorial shows how to use both to retrieve Google Search results. We also show examples of the ADO.NET equivalent, which is possible with the CData ADO.NET Provider for Google Search. To access Google Search results from other .NET applications, like LINQPad, use the CData ADO.NET Provider for Google Search.

Once you have acquired the necessary connection properties, accessing Google Search results in PowerShell can be enabled in three steps.

To search with a Google custom search engine, you need to set the CustomSearchId and ApiKey connection properties.

To obtain the CustomSearchId property, sign into Google Custom Search Engine and create a new search engine.

To obtain the ApiKey property, you must enable the Custom Search API in the Google API Console.

PowerShell

  1. Install the module:

    Install-Module GoogleSearchCmdlets
  2. Connect:

    $googlesearch = Connect-GoogleSearch -CustomSearchId "$CustomSearchId" -ApiKey "$ApiKey"
  3. Search for and retrieve data:

    $searchterms = "WayneTech" $videosearch = Select-GoogleSearch -Connection $googlesearch -Table "VideoSearch" -Where "SearchTerms = `'$SearchTerms`'" $videosearch

    You can also use the Invoke-GoogleSearch cmdlet to execute SQL commands:

    $videosearch = Invoke-GoogleSearch -Connection $googlesearch -Query 'SELECT * FROM VideoSearch WHERE SearchTerms = @SearchTerms' -Params @{'@SearchTerms'='WayneTech'}

ADO.NET

  1. Load the provider's assembly:

    [Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for Google Search\lib\System.Data.CData.GoogleSearch.dll")
  2. Connect to Google Search:

    $conn= New-Object System.Data.CData.GoogleSearch.GoogleSearchConnection("CustomSearchId=def456;ApiKey=abc123;") $conn.Open()
  3. Instantiate the GoogleSearchDataAdapter, execute an SQL query, and output the results:

    $sql="SELECT Title, ViewCount from VideoSearch" $da= New-Object System.Data.CData.GoogleSearch.GoogleSearchDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.title $_.viewcount }