Home > Enterprise >  How to get a specific value from a link? Powershell
How to get a specific value from a link? Powershell

Time:05-14

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!

CodePudding user response:

Do

$LatestChromeRelease = (wget https://chromedriver.storage.googleapis.com/LATEST_RELEASE).Content

CodePudding user response:

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)

CodePudding user response:

Use Invoke-WebRequest

function Get-LatestChromeReleaseVersion{
    $Response = Invoke-WebRequest -URI https://chromedriver.storage.googleapis.com/LATEST_RELEASE
    return $Response.Content    
}

$LatestChromeRelease = Get-LatestChromeReleaseVersion

Write-Host "LatestChromeRelease:"  $LatestChromeRelease
  • Related