Created
December 12, 2020 23:03
-
-
Save Jaykul/e6ea4c75a3f0ad8c131235854eab688c to your computer and use it in GitHub Desktop.
Some simple analysis of updateable help
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filter Get-HelpInfo { | |
<# | |
.SYNOPSIS | |
Get a ((list of) en-US culture-specific?) HelpInfo details (the URL and version number) for modules | |
.EXAMPLE | |
Get-Module Microsoft.* -ListAvailable | Get-HelpInfo | |
#> | |
param( | |
[Parameter(ValueFromPipeline)] | |
[System.Management.Automation.PSModuleInfo]$Module = $((Get-Module WindowsUpdateProvider -List)[0]) | |
) | |
$Path = [IO.Path]::GetTempFileName() | |
if (!([string]$Url = $Module.HelpInfoUri)) { | |
Write-Warning "Can't update help for $($Module.Name). There's no HelpInfoUri in it's manifest $($Module.Path)" | |
return | |
} | |
while($Url) { | |
Write-Verbose "$($Module.Name) HelpInfoUri: $URL" | |
try { | |
Invoke-RestMethod $URL -MaximumRedirection 0 -UseBasicParsing -OutFile $Path | |
break | |
} catch { | |
Write-Verbose "Response: '$($_.Exception.Response.StatusCode)'" | |
if ("Redirect","Moved" -contains $_.Exception.Response.StatusCode) { | |
$Url = $_.Exception.Response.Headers.Location | |
continue | |
} elseif ("NotFound" -eq $_.Exception.Response.StatusCode) { | |
break | |
} | |
# Make sure it's non-terminating | |
Write-Error -ErrorRecord $_ -CategoryTargetName $Module.Name | |
} | |
} | |
$Url = $Url.TrimEnd("/") + "/$($Module.Name)_$($Module.Guid)_HelpInfo.xml" | |
try { | |
Write-Verbose "$($Module.Name) HelpInfoUri: $URL" | |
Invoke-RestMethod $Url -OutFile $Path | |
} catch { | |
Write-Warning "Can't update help for $($Module.Name). Got Status '$([int]$_.Exception.Response.StatusCode) $($_.Exception.Response.ReasonPhrase)' from '$($Url)'" | |
return | |
} | |
if ($Raw) { | |
Get-Content $Path | |
Remove-Item $Path | |
} else { | |
[Xml]$Xml = Get-Content $Path | |
Remove-Item $Path | |
foreach ($Culture in $Xml.HelpInfo.SupportedUICultures.UICulture) { | |
$Culture.PSTypeNames.Insert(0, "HelpContent") | |
[PSCustomObject][Ordered]@{ | |
PSTypeName = "HelpInfo" | |
ModuleName = $Module.Name | |
Culture = $Culture.UICultureName | |
Version = $Culture.UICultureVersion | |
HelpContentURI = $Xml.HelpInfo.HelpContentURI | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment