Ready to get started?

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

 Download Now

Learn more:

Bing Search Icon Bing Search ADO.NET Provider

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

Automate Bing Search Integration Tasks from PowerShell



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

The CData Cmdlets for Bing 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 Bing Search.

PowerShell Cmdlets or ADO.NET Provider?

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

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

To connect to Bing, set the ApiKey connection property. To obtain the API key, sign into Microsoft Cognitive Services and register for the Bing Search APIs.

Two API keys are then generated; select either one.

When querying tables, the SearchTerms parameter must be supplied in the WHERE clause.

PowerShell

  1. Install the module:

    Install-Module BingCmdlets
  2. Connect:

    $bing = Connect-Bing -APIKey "$APIKey"
  3. Search for and retrieve data:

    $searchterms = "WayneTech" $videosearch = Select-Bing -Connection $bing -Table "VideoSearch" -Where "SearchTerms = `'$SearchTerms`'" $videosearch

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

    $videosearch = Invoke-Bing -Connection $bing -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 Bing Search\lib\System.Data.CData.Bing.dll")
  2. Connect to Bing Search:

    $conn= New-Object System.Data.CData.Bing.BingConnection("APIKey=MyAPIKey;") $conn.Open()
  3. Instantiate the BingDataAdapter, execute an SQL query, and output the results:

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