I'm trying to create a script which will parse an URL for a specific exe download link and download it. I'm doing this because the download link changes frequently. Below the code:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$path = "https://www.broadcom.com/support/security-center/definitions/download/detail?gid=sep14"
$definitionPath = (Invoke-WebRequest $path).Links |
Where-Object{$_.InnerText -like "*core15sdsv5i64.exe" -and $_.InnerText -notlike "*.jdb"} |
Select-Object -ExpandProperty href
$Output = "C:\temp\virus_definition.exe"
$start_time = Get-Date
Invoke-WebRequest -Uri $definitionPath -OutFile $Output
I receive one error telling me that the argument "$definitionPath" is empty or null. Any ideas how can i fix that?
Thanks.
You have to select the property that you want explicitly, which you are doing, but not it can be empty, so you have to trap for that possibility.
Personally, I'd refactor to this for a more direct reference