Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One way to obtain the name of a product in SQL from the Microsoft website through PowerShell's Invoke-WebRequest is to parse the HTML response using regular expressions.

Here's an example:

  1. Construct the URL for the product version you're interested in. For example, the URL for SQL Server 2019 is:

    $url = "https://docs.microsoft.com/en-us/sql/sql-server/sql-server-2019-release-notes"
    
  2. Use Invoke-WebRequest to retrieve the content of the webpage:

    $response = Invoke-WebRequest $url
    
  3. Parse the response using regular expressions to extract the product name:

    $pattern = '<h1 class="page-title" itemprop="name">([^<]*)</h1>'
    $productName = $response.Content | Select-String -Pattern $pattern | ForEach-Object { $_.Matches.Groups[1].Value }
    

    This regular expression pattern matches a string enclosed in the <h1> tags with a specific class and itemprop attribute. The Select-String cmdlet searches for this pattern in the response content, and the ForEach-Object cmdlet extracts the captured string from each match found.

  4. The $productName variable now contains the name of the SQL Server product for the specified version.