'How to get a specific value from a link? Powershell
let's imagine I have a link - https://chromedriver.storage.googleapis.com/LATEST_RELEASE where I can get the latest Chrome release version. I need to retrieve this value (101.0.4951.41) and write it to the variable. For example, I create variable
$LatestChromeRelease = https://chromedriver.storage.googleapis.com/LATEST_RELEASE
so the value of this variable would be '101.0.4951.41'
and I can use it in my further actions.
Please advise how to achieve it in PowerShell script. Thanks!
Solution 1:[1]
Do
$LatestChromeRelease = (wget https://chromedriver.storage.googleapis.com/LATEST_RELEASE).Content
Solution 2:[2]
Since the given endpoint returns just the version and nothing else, this is simply a question of sending a web request:
$response = Invoke-WebRequest -Uri 'https://chromedriver.storage.googleapis.com/LATEST_RELEASE' -UseBasicParsing
$version = if($response.StatusCode -eq 200){ $response.Content }
If the request succeeds, $version
now holds the string value "101.0.4951.41"
(or whatever the current latest version number is)
Solution 3:[3]
function Get-LatestChromeReleaseVersion{
$Response = Invoke-WebRequest -URI https://chromedriver.storage.googleapis.com/LATEST_RELEASE
return $Response.Content
}
$LatestChromeRelease = Get-LatestChromeReleaseVersion
Write-Host "LatestChromeRelease:" $LatestChromeRelease
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Prasad Tamgale |
Solution 2 | Mathias R. Jessen |
Solution 3 | Hasta Tamang |