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:
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"
Use Invoke-WebRequest to retrieve the content of the webpage:
$response = Invoke-WebRequest $url
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.
The $productName
variable now contains the name of the SQL Server product for the specified version.