{"id":15891,"date":"2011-01-16T00:01:00","date_gmt":"2011-01-16T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2011\/01\/16\/weekend-scripter-query-the-bing-search-engine-from-a-powershell-script\/"},"modified":"2011-01-16T00:01:00","modified_gmt":"2011-01-16T00:01:00","slug":"weekend-scripter-query-the-bing-search-engine-from-a-powershell-script","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-query-the-bing-search-engine-from-a-powershell-script\/","title":{"rendered":"Weekend Scripter: Query the Bing Search Engine from a PowerShell Script"},"content":{"rendered":"<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><b><span style=\"font-size:10.0pt\">Summary:<\/span><\/b><span style=\"font-size:10.0pt\"> Microsoft MVP Sean Kearney shows how to use the Bing web services API from inside a Windows PowerShell script.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">Microsoft Scripting Guy Ed Wilson here. Sean Kearney is back with us today as he continues to share with us his discoveries while playing. Read more about Sean in the introduction on <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/2010\/12\/19\/weekend-scripter-holiday-powershell-carol-part-one.aspx\">this blog post<\/a>. Let us see what Sean has found while playing again. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">I played some more today. I decided no matter what, I would learn how to interface with Bing.com and Windows PowerShell. I had some excellent pointers from my good buddy and cohort at Tech&middot;Ed <a target=\"_blank\" href=\"http:\/\/blog.syntaxc4.net\">Azure MVP Cory Fowler<\/a> and found the <a target=\"_blank\" href=\"http:\/\/www.bing.com\/developers\/\" title=\"Developers resources Bin.com\">Developers site on Bing.com<\/a> to begin my quest.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">With Bing, you can now pass your information directly via XML or Json. You can even access Bing with SOAP but I&rsquo;ll be honest my SOAP expertise is limited to the bar kind and it is used for bathing. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">XML, for those of use that use Windows PowerShell, is VERY easy to work with. The fact that Bing can return the results in XML format makes it that much better. A number of Hey, Scripting Guys! Blog posts talk about how to work with <a href=\"http:\/\/blogs.technet.com\/b\/heyscriptingguy\/archive\/tags\/windows+powershell\/xml\/\">XML and Windows PowerShell<\/a>. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">When you sign in to <a href=\"http:\/\/www.bing.com\/developers\">www.bing.com\/developers<\/a> there is an excellent link called <b>API Basics<\/b>. Download it, and read it.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">But here? We will cram all that information into a condensed version.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<h2>STEP 1&nbsp;&ndash; GET an AppID<\/h2>\n<p><span style=\"font-size:10.0pt\">Your first task in working with the Bing API is to obtain what is known as an &ldquo;AppID&rdquo;. It is just a long series of numbers unique to your application that will do the searching.&nbsp; Visit <a href=\"http:\/\/www.bing.com\/developers\">www.bing.com\/developers<\/a> and follow the step-by-step process for obtaining an AppID. Without one, you cannot use the XML API.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">You will be presented with a form to complete. See the following figure. This is just a reference information about your application (Yes, your simple Windows PowerShell script to query Bing, or your web browser is an application unto itself) and some details about you, the Developer. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">(But wait I&rsquo;m an ITPRO!) &lt;&#8212; That is ok. We are not going to kick you out of the club for applying for an Application ID.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/5226.WES-1-16-11-01.jpg\" border=\"0\" \/><\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">When you finish all this and accept the EULA&nbsp;(End-User License Agreement) you will have a number assigned to THAT application. You will see it after you have finished on this screen as shown in the following figure.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/5826.WES-1-16-11-02.jpg\" border=\"0\" \/><\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><\/span><\/p>\n<h2>STEP 2&nbsp;&ndash; Form that XML Query as a URL<\/h2>\n<p><span style=\"font-size:10.0pt\">Before we get to Windows PowerShell land we have to figure out what the XML query looks like.&nbsp;A very basic query that searches the web for the text <b>SearchData<\/b> would look like the following line of code. (Keep in mind it is a single logical line of code that is displayed on two lines due to blog formatting. No line continuation characters have been added). <\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">http:\/\/api.bing.net\/xml.aspx?AppId=<b>XXXXXXXXXXXXXXXXXXXX<\/b>&amp;Version=2.2&amp;Market=en-US&amp;Query=<b>SearchData<\/b>&amp;Sources=web<\/span><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">You would replace the <b><i>XXXXXXXXXXXXXXXXXXXX<\/i><\/b> with your numeric AppID that you obtained earlier when you requested your BING AppID. (In our case that number is <b>03340B083932F15ACCD89E2C1D0506D8F61E9CEB<\/b>). The word <b><i>SearchData <\/i><\/b><span>is replaced<b><i> <\/i><\/b><\/span>with whatever you would normally search for on Bing. So let us try a simple example, and search for the word <b>POWERSHELL. <\/b>The command to search Bing using my AppID and the search word PowerShell is seen here (as before it is a single logical line).<\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">http:\/\/api.bing.net\/xml.aspx?AppId=03340B083932F15ACCD89E2C1D0506D8F61E9CEB&amp;Version=2.2&amp;Market=en-US&amp;Query=POWERSHELL&amp;Sources=web<\/span><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">If you were to key this into your browser that you would get a big funky XML document as response. This is seen in the following figure. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><img decoding=\"async\" src=\"https:\/\/msdnshared.blob.core.windows.net\/media\/TNBlogsFS\/prod.evol.blogs.technet.com\/CommunityServer.Blogs.Components.WeblogFiles\/00\/00\/00\/76\/18\/0535.WES-1-16-11-03.jpg\" border=\"0\" \/><\/span><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">Congratulations, you have just formed an XML query. Now we have to make the XML query useful. <\/span><\/p>\n<p><span style=\"font-size:10.0pt\"><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<h2>STEP 3&nbsp;&ndash; Send it with Windows PowerShell<\/h2>\n<p><span style=\"font-size:10.0pt\">This is, of course, over simplifying the power of the Bing API, but today we will stick with simple tasks<span>&nbsp; <\/span>so that you can see how to use it with Windows PowerShell.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">So, these lines will let you form a URL that you can send to the web substituting&nbsp;only the data we have to change for today. The <b>$AppID<\/b> variable accepts your AppID, and the <b>$Query <\/b>variable will accept the search term. The variables are added to the URL as seen here. <\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$AppId=&rdquo;03340B083932F15ACCD89E2C1D0506D8F61E9CEB&rdquo;<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$Query=&rdquo;Powershell&rdquo;<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size:10.0pt\"><span style=\"font-family: courier new,courier\">$URL=&rdquo;<\/span><a href=\"http:\/\/api.bing.net\/xml.aspx?AppId=\"><i><span><span style=\"font-family: courier new,courier\">http:\/\/api.bing.net\/xml.aspx?AppId=<\/span><\/span><\/i><\/a><span style=\"font-family: courier new,courier\">&rdquo;+$AppId+&rdquo;&amp;Version=2.2&amp;Market=en-US&amp;Query=&rdquo;+$Query+&rdquo;&amp;Sources=web&rdquo;<\/span><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">Now to make this work we will connect with <b>SYSTEM.NET.WEBCLIENT<\/b> and pass the URL to the Internet. We will store the result in a boring little variable called, <b>$Result<\/b>.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">We have to prepend <b>$RESULT<\/b> with [XML] to tell Windows PowerShell that the data is coming in as a text stream, but that the text will conform to XML formatting rules. So when Windows PowerShell knows this it does something beautiful. It transforms that XML gibberish stuff&nbsp;into something useful &ndash;R WS and COLUMNS! This portion of the code appears here.<\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$WEB=NEW-OBJECT SYSTEM.NET.WEBCLIENT <\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">[XML]$RESULT=$WEB.DownloadString($URL)<\/span><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<h2>STEP 4&nbsp;&ndash; Parse and View Results<\/h2>\n<p><span style=\"font-size:10.0pt\">At this point, I am almost tempted to put on a Julia Child voice and say, &ldquo;And now, we remove the pie from the oven and enjoy&hellip;&rdquo; But I won&rsquo;t.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">Now that you have the <b>$RESULT<\/b> variable full of results that you may want to actually use it. You could run a <b>Get-Member<\/b> on it, but XML is actually very nice to work with. Just type the variable name <b>$RESULT<\/b> in your Windows PowerShell console, and it will immediately reveal the available parts of the tree.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">So with <b>$RESULT<\/b> there is value within it called <b>SearchResponse<\/b>, within <b>SearchResponse<\/b> is &ldquo;<b>Web<\/b>&rdquo;. How did I tell that? I keyed into the Windows PowerShell Console directly. This is seen here. <\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$RESULT<\/span><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">The <b>$Result<\/b> variable reveals the following information. <\/span><\/p>\n<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"MsoNormalTable\" style=\"width: 563px;margin-left: 0.5in\">\n<tbody>\n<tr>\n<td width=\"169\" valign=\"top\" style=\"width: 126.75pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">xml<\/span><\/span><\/p>\n<\/td>\n<td width=\"157\" valign=\"top\" style=\"width: 117.85pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">pageview_candidate<\/span><\/span><\/p>\n<\/td>\n<td width=\"237\" valign=\"top\" style=\"width: 177.65pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">SearchResponse<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"169\" valign=\"top\" style=\"width: 126.75pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;<\/span><\/span><\/p>\n<\/td>\n<td width=\"157\" valign=\"top\" style=\"width: 117.85pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/span><\/span><\/p>\n<\/td>\n<td width=\"237\" valign=\"top\" style=\"width: 177.65pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;&#8212;&#8212;&#8212;&#8211;<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"169\" valign=\"top\" style=\"width: 126.75pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">version=&#8221;1.0&#8243; encoding=&#8230;<\/span><\/span><\/p>\n<\/td>\n<td width=\"157\" valign=\"top\" style=\"width: 117.85pt;padding: 1.5pt\"><span style=\"font-family: courier new,courier\"><\/span><\/td>\n<td width=\"237\" valign=\"top\" style=\"width: 177.65pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">SearchResponse<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">When I query the <b>SearchResponse <\/b>property of the XML object that is stored in the <b>$Result<\/b> variable, it reveals the following information.<\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$RESULT.SearchResponse<\/span><\/span><\/p>\n<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"MsoNormalTable\" style=\"width: 415px;margin-left: 33.1pt\">\n<tbody>\n<tr>\n<td width=\"163\" valign=\"top\" style=\"width: 122.05pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">xmlns<\/span><\/span><\/p>\n<\/td>\n<td width=\"95\" valign=\"top\" style=\"width: 71.45pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Version<\/span><\/span><\/p>\n<\/td>\n<td width=\"84\" valign=\"top\" style=\"width: 63pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Query<\/span><\/span><\/p>\n<\/td>\n<td width=\"73\" valign=\"top\" style=\"width: 54.6pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Web<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"163\" valign=\"top\" style=\"width: 122.05pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;&#8211;<\/span><\/span><\/p>\n<\/td>\n<td width=\"95\" valign=\"top\" style=\"width: 71.45pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;&#8212;-<\/span><\/span><\/p>\n<\/td>\n<td width=\"84\" valign=\"top\" style=\"width: 63pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;&#8211;<\/span><\/span><\/p>\n<\/td>\n<td width=\"73\" valign=\"top\" style=\"width: 54.6pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"163\" valign=\"top\" style=\"width: 122.05pt;padding: 1.5pt\">\n<p style=\"margin-left: 0.5in\"><span style=\"font-family: courier new,courier\"><span style=\"font-size: 10pt\">http:\/\/schemas.m<\/span><span style=\"font-size: 10pt\">&#8230;<\/span><\/span><\/p>\n<\/td>\n<td width=\"95\" valign=\"top\" style=\"width: 71.45pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">2.2<\/span><\/span><\/p>\n<\/td>\n<td width=\"84\" valign=\"top\" style=\"width: 63pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Query<\/span><\/span><\/p>\n<\/td>\n<td width=\"73\" valign=\"top\" style=\"width: 54.6pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Web<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">When I query the Web property, it reveals additional information that is seen here. <\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$RESULT.SearchResponse.Web<\/span><\/span><\/p>\n<p><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&nbsp;<\/span><\/span><\/p>\n<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"MsoNormalTable\" style=\"width: 494px;margin-left: 33.1pt\">\n<tbody>\n<tr>\n<td width=\"163\" valign=\"top\" style=\"width: 122.1pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">web<\/span><\/span><\/p>\n<\/td>\n<td width=\"106\" valign=\"top\" style=\"width: 79.5pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Total<\/span><\/span><\/p>\n<\/td>\n<td width=\"107\" valign=\"top\" style=\"width: 79.95pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Offset<\/span><\/span><\/p>\n<\/td>\n<td width=\"119\" valign=\"top\" style=\"width: 88.95pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Results<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"163\" valign=\"top\" style=\"width: 122.1pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;<\/span><\/span><\/p>\n<\/td>\n<td width=\"106\" valign=\"top\" style=\"width: 79.5pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;&#8211;<\/span><\/span><\/p>\n<\/td>\n<td width=\"107\" valign=\"top\" style=\"width: 79.95pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;&#8212;<\/span><\/span><\/p>\n<\/td>\n<td width=\"119\" valign=\"top\" style=\"width: 88.95pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">&#8212;&#8212;-<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td width=\"163\" valign=\"top\" style=\"width: 122.1pt;padding: 1.5pt\">\n<p style=\"margin-left: 0.5in\"><span style=\"font-family: courier new,courier\"><span style=\"font-size: 10pt\">http:\/\/schemas.m<\/span><span style=\"font-size: 10pt\">&#8230;<\/span><\/span><\/p>\n<\/td>\n<td width=\"106\" valign=\"top\" style=\"width: 79.5pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">73500<\/span><\/span><\/p>\n<\/td>\n<td width=\"107\" valign=\"top\" style=\"width: 79.95pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">0<\/span><\/span><\/p>\n<\/td>\n<td width=\"119\" valign=\"top\" style=\"width: 88.95pt;padding: 1.5pt\">\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">Results<\/span><\/span><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">No wait, we are not done yet! When I look at the <b>Results<\/b> property, it also returns additional information. It is shown here. <\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$RESULT.SearchResponse.Web.Results<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">WebResult<br \/>&#8212;&#8212;&#8212;<br \/>{web:WebResult, web:WebResult, web:WebResult, web:WebResult&#8230;}<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">To see our results from the search we have to query the WebResult property as seen here. <\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$RESULT.SearchResponse.Web.Results.Webresult<\/span><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">After you run that you will probably want to do a <b>Format-Table<\/b> to see what columns are available. The command to do this is shown here. <\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$RESULT.SearchResponse.Web.Results.Webresult | FORMAT-TABLE<\/span><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">From this point forward, you can work with that data in whatever manner you want. Query it, export it to .csv, and pass those links to the web &#8211; whatever strikes you as useful or interesting &#8211; maybe even something as simple as returning a list of URL&rsquo;s, together with the title and the description as shown here. <\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$RESULT.SearchResponse.Web.Results.Webresult | SELECT-OBJECT Url, Title, Description<\/span><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">However, here is where we make it simpler. A function called <b><span>SEARCH-BING <\/span><\/b><span>that will make it easier to search Bing from Windows PowerShell. <\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">function global:SEARCH-BING( $Query )<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">{<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size:10.0pt\"><span style=\"font-family: courier new,courier\"># AppID you Acquired from <\/span><a href=\"http:\/\/www.bing.com\/developers\"><b><span><span style=\"font-family: courier new,courier\">www.bing.com\/developers<\/span><\/span><\/b><\/a><br \/><span style=\"font-family: courier new,courier\">$AppId=&rdquo;03340B083932F15ACCD89E2C1D0506D8F61E9CEB&rdquo;<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size:10.0pt\"><br \/><span style=\"font-family: courier new,courier\"># XML Query to pass to Bing.com<br \/>$URL=&rdquo;<\/span><a href=\"http:\/\/api.bing.net\/xml.aspx?AppId=\"><b><span><span style=\"font-family: courier new,courier\">http:\/\/api.bing.net\/xml.aspx?AppId=<\/span><\/span><\/b><\/a><span style=\"font-family: courier new,courier\">&rdquo;+$AppId+&rdquo;&amp;Version=2.2&amp;Market=en-US&amp;Query=&rdquo;+$Query+&rdquo;&amp;Sources=web&rdquo;<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size:10.0pt\"><br \/><span style=\"font-family: courier new,courier\"># Connect to the Web and download XML data from provided URL<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">$WEB=NEW-OBJECT SYSTEM.NET.WEBCLIENT<br \/>[XML]$RESULT=$WEB.DownloadString($URL)<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size:10.0pt\"><br \/><span style=\"font-family: courier new,courier\"># Return the goodies back home to Grandma<br \/>RETURN $RESULT<\/span><\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">}<\/span><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">After you use it you can type the following command:<\/span><\/p>\n<p style=\"margin-left:0.5in\"><span style=\"font-size: 10pt\"><span style=\"font-family: courier new,courier\">SEARCH-BING &ldquo;The Answer to Life the Universe and EVERYTHING&rdquo;<\/span><\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">There you have it. A function that you can take with you to search Bing.com in your environment. Take note, you will have to replace THIS AppId with your own because I&rsquo;ve already deleted&nbsp;it from Bing &nbsp;and don&rsquo;t forget, we&rsquo;ve only TOUCHED the surface of a Bing.com search.&nbsp;But hopefully I&rsquo;ve unlocked the box and you can take it from there.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">The Power of Shell (and BING) is in YOU.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">Sean, thank you for sharing what you learned while playing around. I wonder what you would learn if you were really working at it? <\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">I invite you to follow me on <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingguystwitter\">Twitter<\/a> or <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\">Facebook<\/a>. If you have any questions, send email to me at <a target=\"_blank\" href=\"mailto:scripter@microsoft.com\">scripter@microsoft.com<\/a> or post them on the <a target=\"_blank\" href=\"http:\/\/bit.ly\/scriptingforum\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/span><\/p>\n<p><span style=\"font-size:10.0pt\">&nbsp;<\/span><\/p>\n<p><b><span style=\"font-size:10.0pt\">Ed Wilson, Microsoft Scripting Guy<\/span><\/b><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Summary: Microsoft MVP Sean Kearney shows how to use the Bing web services API from inside a Windows PowerShell script. &nbsp; Microsoft Scripting Guy Ed Wilson here. Sean Kearney is back with us today as he continues to share with us his discoveries while playing. Read more about Sean in the introduction on this [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[56,3,154,167,214,61,45],"class_list":["post-15891","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-guest-blogger","tag-scripting-guy","tag-sean-kearney","tag-using-the-internet","tag-web-services","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>&nbsp; Summary: Microsoft MVP Sean Kearney shows how to use the Bing web services API from inside a Windows PowerShell script. &nbsp; Microsoft Scripting Guy Ed Wilson here. Sean Kearney is back with us today as he continues to share with us his discoveries while playing. Read more about Sean in the introduction on this [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/15891","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=15891"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/15891\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=15891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=15891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=15891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}