Ask Your Question
2

How can the name of a product in SQL be obtained using its version from the Microsoft website through Powershell's Invoke-webrequest?

asked 2022-04-07 11:00:00 +0000

pufferfish gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-05-06 10:00:00 +0000

david gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-04-07 11:00:00 +0000

Seen: 12 times

Last updated: May 06 '22