Forum Discussion
PowerShell Invoke-WebRequest trouble with links
SalahTN the short answer is, it's null because your Where-Object filter is filtering out all of the potential links.
Longer answer:
Stepping through it, this:
(Invoke-WebRequest $path).Links
Returns three links. Two of the links are about the site's Cookie Policy and the third is OneTrust badge of some description, none of these match your filter for the exe file you're looking for.
What you'll find, if you call Invoke-WebRequest and look at the HTML of the page that's returned... most of the content you see in the browser is "inside" a script and PowerShell can't parse the links as it doesn't see them.
One thing you can try is the Selenium PowerShell Module. Note, to use it you do need the beta version, otherwise it won't work with newer versions of Chrome, and this means you may need to update PowerShellGet.
Selenium loads up a full Chrome (or FireFox, etc.) browser, which you can do headless so you don't see it pop up. You should be able to find the link you're looking for. I can't do the full code here, but you'll want to use Find-SeElement, you're looking for an 'a' tag with the text you're looking for.
Once you've found it, you can "click" the link to download it via the browser, or just grab the link and download as you're trying to do.
The first time you do a Selenium script, there's probably a learning curve to it, but it's a *super* powerful toll to add to your toolbox. Browser automation like this opens up a lot of possibilities, I use it for an old RMM tool that doesn't have a nice API.