Home > Software engineering >  I want to get the version number of Power-BI from the website and the -match is true but I can not s
I want to get the version number of Power-BI from the website and the -match is true but I can not s

Time:11-23

 $Uri = 'https://aka.ms/pbiSingleInstaller'
   $web = Invoke-WebRequest -Uri $uri 
   $url=$web.Links |Where-Object href -Like "*confirmation*" | Select-Object -expand href 
 ( $downloadurlid = "https://www.microsoft.com/en-us/download/"   $url )
   $idcontent = Invoke-WebRequest -Uri $downloadurlid 
 ( $downloadurl = $idcontent.Links |Where-Object href -Like "*x64.exe" | Select-Object -First 1 -expand href )
   $a = $web.Content
(  $a -match "\d*.\d*.\d*.\d* " )
 ( $latestversion = "$($Matches[1])")
 ( $FileName = $downloadurl.Split('/')[-1])

here is my script I want to get the version number which is here(https://www.microsoft.com/en-us/download/details.aspx?id=58494) like Version:

2.110.1161.0 , the match returns true but I can not see the result can someone help me how I can get the version number? thanks in advance

CodePudding user response:

Regex \d*.\d*.\d*.\d* is a problem here. \d*. matches 0 or more digits followd by any character, so full regex matches any three characters before space, even if there were no digits.
First tag in $web.Content was <!DOCTYPE html >, so $Matches now contains YPE .

Try $web.Content -match 'd\ .\d \.\d \.\d '. \d means at least one digit, and \. a dot (. without escape \ means any character).
It now finds version number, but please note that using regex to parse html document can yield incorrect results if page content changes in the future. It'd be safer to use xPath for that.

  • Related