This blog is part of a series that shows example PowerShell code for those learning the language.
This time we’re using PowerShell to find out which PowerShell cmdlet in a specific module is the most popular. To do this, we’re using a Bing search and producing a list with the name and number of web pages found for each one. This is returned as an object, so you can pipe the output to sort or filter. The name of the module is hard coded to “SmbShare”, but you can replace it with any valid module name. You could also make a parameter.
This example explores using the Web client in the .NET System.Web assembly, searching through the resulting web page using string functions, showing cmdlet progress and also a trick to create an object on the fly. It also shows more common items like arrays and functions.
|
# # # Adds assembly to support URL encoding and the web client Add-Type -Assembly System.Web Function Get-BingCount([string] $Term) { # Add plus and quotes, encodes for URL # Load the page as a string # searches for the string before the number of hits on the page # if found the right string, finds the exact end of the number # Return the count # $CmdletList = Get-Command -Module SmbShare | Select Name 0..$CmdletCount | % { # Tracks progress # Check the popularity with Bing # Format as a row, output it Write-Progress -Activity "Checking cmdlet popularity" -Completed # Releases resources used by the web client |
In case you were wondering what the output would look like, here is a sample:
these terminology of computer language is difficult to understand but when it comes out as a result it looks good… so i like it..
http://www.hexder.com/categories/Movie-Jackets/
LikeLike
If you follow the blog, you probably saw a little PowerShell script I published a while back to measure
LikeLike