# encoding: ascii
# api: powershell
# title: Get-HelpInfo - PS V3
# description: Shows information about locally installed help files for your modules, alongside the available version online should you run update-help. This is for powershell 3.0 only. With thanks to Shay and Alexandair for useful snippets.
# version: 0.1
# type: function
# author: Oisin Grehan
# license: CC0
# function: Get-HelpInfo
# x-poshcode-id: 3712
# x-archived: 2015-05-06T21:13:09
# x-published: 2015-10-24T11:01:00
#
#
#requires -version 3

function Get-HelpInfo {

    write-progress -id 1 -Activity "Get-HelpInfo" -Status "Getting remote version table..."

    # could cache this
    $remote = & {
        $html = invoke-webrequest http://technet.microsoft.com/en-us/windowsserver/jj662920
        $html.ParsedHtml.getElementsByTagName("TABLE").item(2).rows| % -begin {
            $total = $html.ParsedHtml.getElementsByTagName("TABLE").item(2).rows.length
            $index = 0
        } -process {
            write-progress -id 1 -Activity "Get-HelpInfo" -Status "Getting remote version table..." `
                -PercentComplete (([float]$index / $total) * 100)
		    ($_.cells | % innertext) -join ","
            $index++
        } | convertfrom-csv
	}

    write-progress -id 1 -Activity "Get-HelpInfo" -Status "Enumerating local modules..." `
        -CurrentOperation "Please wait..."

    # could cache "gmo -list" output too - it's dog slow, and no way to get progress either.
    gmo -list | ? {
        write-progress -id 1 -Activity "Get-HelpInfo" -Status "Examining $($_.name) ..."
        test-path ($info = join-path (split-path $_.path) `
            ("{0}_{1}_HelpInfo.xml" -f $_.name, $_.guid))
    } | % {
        $name = $_.Name
        ([xml](gc $info)).HelpInfo.SupportedUICultures.UICulture
    } | % {
        [pscustomobject]@{
            ModuleName = $name
            UICulture = $_.UICultureName
            Installed = $_.UICultureVersion
            Available = ($remote|? { ($_.modulename -eq $name) -and $_.uiculture `
                -contains $_.uiculturename } ).version
        }
    }
}

get-helpinfo | ft -AutoSize
