The other day I was looking for a Powershell one-liner to get the content of a URL and came across this superuser post, which suggested to take a look into
Invoke-WebRequest or wget (an alias of
Invoke-WebRequest). My usage was to pull in the content of this text file during a build on a remote TeamCity build agent. For some context, these build agents are configured and automated by Chef.
This approach was a little naive:
$content = (wget $url).Content
As when I kicked off the build I was surprised to see this…
wget : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.
Urgh… so it’s dependant on IE and it looks like I should have gone through the first-launch wizard? Not such a good idea if you are bringing these boxes up in an automated manner. If you see this and you are using
wget, you might want to consider using some of the sauce that Chocolatey uses to download it’s install script by creating an instance of a .NET WebClient i.e.
In my case, I took my wget and replaced it with:
$content = (new-object net.webclient).DownloadString($url)
Which, though slightly more verbose, doesn’t have this dependency on IE, good for the fact I’m hoping I never need to remote onto these boxes.