liveBook · Manning

ConvertFrom-Html

As explained in Practical Automation with PowerShell: Effective scripting from the console to the cloud

ConvertFrom-Html is a command that converts HTML input into structured PowerShell objects, including HTML node data.

ConvertFrom-Html, supplied by the PowerHTML module, turns HTML from a URI or supplied content into a navigable document object. Use that object to select HTML nodes with XPath instead of treating a web page as unstructured text. section 13.3 section 13.3.1

A practical scraping flow builds a search URL, converts its results page, identifies every matching link with a stable XPath, then converts each details page. This accommodates multiple catalog results for one KB article rather than assuming a single match. section 13.3.1

Work with the returned node object by separating page selection from value cleanup:

  • Use browser inspection and copied element markup to find attributes that remain consistent across result links; avoid an XPath tied to one changing element ID. section 13.3.1
  • Call SelectNodes for repeated elements and SelectSingleNode for a known details container, then read properties such as Id and InnerText. section 13.3.1
  • Clean extracted text with Replace, Trim, and Split, or shape link data into custom objects with KB number, title, and ID. section 13.3.1
  • Retrieve a details page with Invoke-WebRequest and request headers when needed, then pass the response content to ConvertFrom-Html. section 13.3.1

Find update supersedence

For KB4521858, select all search-result links, remove each link’s _link suffix to form a ScopedViewInline details URL, and convert that page. XPath queries then retrieve architecture, supported products, and superseding-update links; regex extraction can turn those links into KB records. section 13.3.1

$xPath = '//*[' +
    '@class="contentTextItemSpacerNoBreakLink" ' +
    'and @href="javascript:void(0);"]'
$Search.SelectNodes($xPath) | Format-Table NodeType, Name, Id, InnerText
NodeType Name AttributeCount ChildNodeCount ContentLength InnerText
-------- ---- -------------- -------------- ------------- ---------
Element  a    4              1              144           ...
Element  a    4              1              148           ...
Element  a    4              1              148           ...

This XPath selects every result link sharing the observed class and href attributes, returning nodes whose IDs and text can drive later requests. section 13.3.1

How Practical Automation with PowerShell: Effective scripting from the console to the cloud covers it

How deep it goes
Demonstrates URI and content conversion, XPath selection, text cleanup, and custom-object output without detailing HTML parser internals.
Examples
Uses KB4521858 search results and update detail pages to extract architecture, products, and superseding KB links.
What it assumes
Starts XPath discovery through browser inspection rather than requiring prior XPath-writing skill.
What you can do after
Apply it via PowerHTML to navigate HTML nodes and assemble structured patch records from catalog pages.
How it connects
Connects HTML parsing with XPath, Invoke-WebRequest, regular expressions, custom objects, and web scraping.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practical Automation with PowerShell: Effective scripting from the console to the cloud. The section links point to the parts of the book it draws on.