Quantcast
Channel: Category Name
Viewing all articles
Browse latest Browse all 5932

The Most Popular Hyper-V PowerShell Cmdlets - by Bing

$
0
0

Last week Jose Barreto made an excellent post about using PowerShell and Bing to check the popularity of various SMB PowerShell cmdlets.  Well, I could not resist doing the same with Hyper-V!  I made a slight tweak to Jose's code - by storing my data in a hashtable.  This made it easier to sort and output for later use.  Here is the code I used:

Add-Type -Assembly System.Web
$WebClient = New-Object system.Net.WebClient

Function Get-BingCount([string] $Term) {

    # Add plus and quotes, encodes for URL
    $Term = '+"' + $Term + '"'
    $Term = [System.Web.HttpUtility]::UrlEncode($Term)

    # Load the page as a string
    $URL = "http://www.bing.com/search?q=" + $Term
    $Page = $WebClient.DownloadString($URL)

    # searches for the string before the number of hits on the page
    $String1 = ''
    $Index1 = $Page.IndexOf($String1)

    # if found the right string, finds the exact end of the number
    If ($Index1 -ne -1) {
        $Index1 += $String1.Length
        $Index2 = $Page.IndexOf(" ", $Index1)
        $result = $Page.Substring($Index1, $Index2 - $index1)
    } else { $result = "0" }

    # Return the count
    return $result
}

$CmdletList = Get-Command -Module Hyper-V | Select Name
$CmdletCount = $CmdletList.Count -1
$hashTable = $null
$hashTable = @{}

0..$CmdletCount | % {

    # Tracks progress
    Write-Progress -Activity "Checking cmdlet popularity" -PercentComplete ($_ * 100 / $CmdletCount)

    # Check the popularity with Bing
    $cmdlet = $CmdletList[$_].Name
    $count = [int] (Get-BingCount $cmdlet)

    # Put data in a hashtable
    $hashTable.add($cmdlet, $count)
}

$hashTable.GetEnumerator() | sort value -Descending | select @{N="Cmdlet";E={$_.Name}}, @{N="Popularity";E={$_.Value}}

Write-Progress -Activity "Checking cmdlet popularity" -Completed

# Releases resources used by the web client
$WebClient.Dispose()

And the results?  Well - I am happy to let you know the top twenty Hyper-V PowerShell cmdlets are as follows:

CmdletPopularity
----------------
New-VM411000
Get-VM91400
Start-VM81300
Set-VM66300
Convert-VHD60700
Mount-VHD55900
Export-VM49900
New-VHD44600
Move-VM44600
Stop-VM42700
Remove-VM42000
Import-VM41100
Get-VMHost29500
Save-VM26400
Resize-VHD24600
Restart-VM24200
Test-VHD22100
Get-VHD17900
Suspend-VM16900
Resume-VM14300
Compare-VM14100

Cheers,
Ben 


Viewing all articles
Browse latest Browse all 5932

Trending Articles