Topics


Blogs


Forums


Samples


Media


Labs


Resources

 




DevCentral > Weblogs > Joe Pruitt - A Software Architect's take on Network Security
 Introducing PoshBing – The PowerShell library for Microsoft’s Bing Search Engine
posted on Wednesday, June 03, 2009 1:02 PM

PoshBing Microsoft released their new search engine called “Bing” at, aptly named, http://www.bing.com.  Microsoft is getting positive reviews from the likes of CNET, The Wall Street Journal, and TechCrunch.  Instead of posting my review of the site, I’ll let you browse the above links to find out what the services is all about.

What interested me about Bing is that Microsoft has released a full API to allow you to use their services in your applications.  The Bing API is documented at Microsoft’s developer site and I thought to myself how I could test it out.  The obvious answer was PowerShell of course.  My previous PoshTweet Twitter Library has been fairly popular so I figured I’d give a “library” type project another go around and tackle the Bing APIs.

The Bing API has the concept of “SourceTypes” which are essentially data sources that you can search into.  My script library provides access to the Image, InstantAnswer, News, MobileWeb, Phonebook, RelatedSearch, Spell, Web, Translation, and Video SourceTypes with the following functions:

  • Get-BingImage – Search the Image SourceType for a list of images including properties about the media files.
  • Get-BingInstantAnswer – Get single, authoritative answers to questions.
  • Get-BingNews – Provide news specific to a topic, a location, or breaking news.
  • Get-BingMobileWeb – Returns mobile web results, primarily relevant XHTML or WML pages.
  • Get-BingPhonebook – Enables you to view details about a business for which you are searching as if they were a phonebook entry.
  • Get-BingRelatedSearch – View searches that provide information in which you might be interested, based on your current search.
  • Get-BingSpell – Query alternative spellings for a given word or phrase.
  • Get-BingWeb – Get pages relevant to the queried terms.
  • Get-BingTranslation – Translate a term from one language to another.
  • Get-BingVideo – return a list of videos and their properties relevant to the query terms.

I’ve included parsing for the response streams for the above SourceTypes, but if you would like to get the raw XML back, all of the above functions include a “-raw” parameter to allow you to bypass the response processing.

 

*Update* 

This little script has taken on a life of it’s own.  As a consequence, I’ve created a project on CodePlex.com to manage the distributions.  You can access it now at the following link:

http://poshbing.codeplex.com

Enjoy!



 
      

Feedback


6/3/2009 5:22 PM
Gravatar Hey Joe

Thanks for posting some great code. Any reason you chose [bool]raw over [switch]raw?


Doug

6/3/2009 7:09 PM
Gravatar If you are looking to follow this series, be sure to subscribe to my RSS feed at http://feeds.jasongaylord
Jason N. Gaylord's Blog

6/3/2009 8:20 PM
Gravatar If you are looking to follow this series, be sure to subscribe to my RSS feed at http://feeds.jasongaylord.com/JasonNGaylord
ASPInsiders

6/4/2009 12:54 AM
Gravatar Looks awesome, but I have a most certainly n00b PowerShell question, but how do I add this library to PowerShell?
Geir-Tore Lindsve

6/4/2009 2:17 AM
Gravatar Never mind, I figured it out. Added a profile folder for PS and put the script there and it works.
Geir-Tore Lindsve

6/4/2009 7:18 AM
Gravatar @Geri-Tore Lindsve - Another options to just "dot source" the script file.

PS> . .\PoshBing.ps1

That will load all the functions into your current runspace. If you want them always available you can . source it in your $profile as well.

-Joe
Joe Pruitt

6/4/2009 7:19 AM
Gravatar @Doug - No reason, just figured since it's values were true of false, I'd use a boolean.

-Joe
Joe Pruitt

6/5/2009 5:50 AM
Gravatar Joe, your use of write-host is killing me here! :) Why didn't you use write-output instead? I'd much prefer to see custom object output that I can then pipe to wherever. Text is dead--come on, you know that! The very first thing I tried to do was get-bingimage | out-gridview and of course..nothing happens. The very next thing I had planned on doing was to pipe it to a script that would use PowerBoots to show the images...

PoshBing v2 perhaps? :)
Hal Rottenberg

6/5/2009 7:30 AM
Gravatar @Hal, I've already made a bunch of those changes and write-host is gone from my current code. That's the problem with getting things out early... I'll post when I've got the object-based output finalized.

-Joe
Joe Pruitt

6/5/2009 8:52 AM
Gravatar Should be good to go now. Get-BingNews "FFIV" | out-gridview now works B-). Thanks for the feedback!!!

-Joe
Joe Pruitt

6/5/2009 11:21 AM
Gravatar It appears this only works with PowerShell version 2. Is that right? It choked on Export-ModuleMember when I ran it on version 1.
John

6/5/2009 12:07 PM
Gravatar Sorry about that. Comment out the Export-ModuleMember or download the latest version.

-Joe
Joe Pruitt

6/8/2009 1:16 AM
Gravatar Microsoft released their new search engine called “Bing” at, aptly named, http://www.bing.com . … The
PowerShell sur Technet et en français

6/9/2009 8:33 AM
Gravatar Hmmm...another PS noob here...

Tried running
.\PoshBing.ps1
but it still doesn't give me access to the functions. The output is below...can anyone advise?

thanks
Jamie

PS C:\Users\jamie.thomson> .\PoshBing.ps1

Security Warning
Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your
computer. Do you want to run C:\Users\jamie.thomson\PoshBing.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"): R
PS C:\Users\jamie.thomson> Get-BingInstantAnswer
The term 'Get-BingInstantAnswer' is not recognized as a cmdlet, function, operable program, or script file. Verify the
term and try again.
At line:1 char:21
+ Get-BingInstantAnswer <<<<
PS C:\Users\jamie.thomson> Get-ExecutionPolicy
Unrestricted
PS C:\Users\jamie.thomson>
Jamie Thomson

6/9/2009 8:37 AM
Gravatar PS> .\PoshBing.ps1 will run the script. Since there are only function declarations inside the script and no actual commands, just running the .ps1 will not do anything. You need to "dot source" the file which basically loads all the definitions into your current runspace.

PS> . .\PoshBing.ps1

If you get a warning about trusted scripts, you may need to set your execution policy down with "Set-ExecutionPolicy Unrestricted". I probably should sign this script so that folks don't get that error...

Let me know if this does or doesn't work for you.

-Joe
Joe Pruitt

6/9/2009 8:44 AM
Gravatar Hey Joe,
Thank you very much for the reply.

Really REALLY showing my lack of POSH knowlege here but..... surely typing "..\PoshBing.ps1" simply looks for the script in the parent of the current folder?
It does on my machine and hence of course it doesn't find it there!

The term '..\PoshBing.ps1' is not recognized as a cmdlet, function, operable program, or script file. Verify the term a
nd try again.
At line:1 char:15

Sorry for the ongoing questioning...
-Jamie
Jamie Thomson

6/9/2009 8:52 AM
Gravatar DOH! Ignore the above, I've figured out how to call the functions now!

Sorry for the comment spam!!!
Jamie Thomson

6/9/2009 11:08 AM
Gravatar Glad you figured it out. There's a space between the first "." and the .\PoshBing.ps1. Type "help about_scope" at the PowerShell prompt for more details on dot sourcing a file.

-Joe
Joe Pruitt

6/9/2009 1:46 PM
Gravatar No problem!

Powershell over Bing = geek coolness
(http://blogs.conchango.com/jamiethomson/archive/2009/06/09/powershell-over-bing-geek-coolness.aspx)
Jamie Thomson

6/11/2009 12:07 PM
Gravatar Great!!

http://www.searchengines.pl/PoshBing-t126104.html
Kolega Dudysa

6/12/2009 2:22 PM
Gravatar This week on Channel 9, Brian and Dan cover the top developer news, including: - XNA Game Studio 3.1
ComponentGear.com Feed

6/18/2009 6:27 AM
Gravatar Joe,
I suspect you already know this but in case you don't.... PoshBing got covered on last week's "This week on Channel 9" (http://channel9.msdn.com/shows/This+Week+On+Channel+9/This-week-on-C9-XNA-updates-Win-7-Training-VS-2010-build-your-own-arcade/)

I feel slightly embarrassed cos they used a screenshot from my blog (:|) but at least you got the credit in the show notes!!

-Jamie
Jamie Thomson

6/9/2009 11:49 AM
Gravatar Thanks Joe!
Seeing as I'm getting lots of useful info here, one more question if I may. Is there any way to suppress the following security warning:

Security Warning
Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your
computer. Do you want to run C:\Users\...\Powershell Scripts\PoshBing.ps1?
[D] Do not run [R] Run once [S] Suspend [?] Help (default is "D"):

Or does the script need to be signed?

thanks
Jamie
Jamie Thomson

6/9/2009 11:56 AM
Gravatar Jamie, you can try lowering your execution policy with "Set-ExecutionPolicy Unrestricted" and see if that helps.

I'll look into signing the script when it get's to production level.

Once you have . sourced the file, you shouldn't get security warnings when trying to execute the functions.

-Joe
Joe Pruitt

6/9/2009 12:03 PM
Gravatar Joe,
Yep, I've already got my exec policy set to Unrestricted.

I've got the Codeplex RSS feed on my reader so I'll know when you productionise it - thanks for that!

Indeed, no hassle running the funcs - all working very nicely indeed. Love it in fact - gonna blog this in the next hour or so.

I'm particularly loving get-bingtranslation!

-Jamie
Jamie Thomson

6/9/2009 12:05 PM
Gravatar Jamie, have you checked out @askbing on twitter? I combined my PoshBing and PoshTweet libraries into a PowerShell twitter bot.

Thanks for the linking as well!

-Joe
Joe Pruitt

7/22/2009 7:19 AM
Gravatar Thanks for Codeplex. Its quite awesome. And I must say, that Bing, is very good. Although it may not be able to compete with or replace google, I have found that the results it provides are much more relevant than google in some searches.
Free Dazzling White Trial

7/22/2009 8:17 AM
Gravatar It seems to have really taken off, considering it got coverage from CNN. That is some achievement. Also, does it not work with power shell version 1? I couldn't get it to run.

Tim from Free Stuff
Tim

7/22/2009 8:18 AM
Gravatar It seems to have really taken off, considering it got coverage from CNN. That is some achievement. Also, does it not work with power shell version 1? I couldn't get it to run.
Free Stuff

7/29/2009 12:50 AM
Gravatar wow, your coding skills are amazing, how long have you been doing it for?
chris

7/29/2009 1:43 AM
Gravatar thanks for the article.
i didn't know anything about poshbing and the artcle tell me what is it.
great article.
keep posting!
Jonas

7/29/2009 8:12 PM
Gravatar Thanks a lot for the lovely article
technology forum

8/1/2009 4:47 AM
Gravatar Wow bing is nice.
But i think google is better than Bing.
because many people use google for search something.

Thanks for the article.
Fast Proxy

8/8/2009 5:19 PM
Gravatar Great work. I want to see bing do more.
Myspace Proxy

8/14/2009 10:13 PM
Gravatar thanks for bing
Carry Willis

8/21/2009 3:09 PM
Gravatar This PoshBing looks like a pretty cool thing I must say!
mcdonalds coupons

8/31/2009 10:06 AM
Gravatar Bing has been a pleasant surprise
George

11/18/2009 10:52 AM
Gravatar Ever since Bing became a part of the competition, everyone has been talking positive things about it and I guess it just lived up to the people expectations.
maybelline dream matte mousse

11/18/2009 6:22 PM
Gravatar Microsoft is a big competitor of Google, now that this two search engines are the most competitive search engines they want to improve search mechanisms

best anti aging moisturizer
best anti aging moisturizer
 Leave Feedback
Title  
Name  
Email
Url
Comments   
Please add 6 and 4 and type the answer here: