Q:

Need a one-liner powershell command to download a file with basic authentication

Setting up some CI stuff. I need a one-liner powershell command to download a file with basic authentication from a server.
I'm able to do it with an unauthenticated request like so:
iex ((New-Object Net.Webclient).DownloadString('http://myhost.example/resource.etc'))

How would I do the same but with authentication? From How to make an authenticated web request in Powershell?, I can see I need a NetworkCredential, just trying to figure out how to condense this to a single command.

A:

This is how to download a string using authentication with a oneliner powershell
iex(((new-object System.Net.WebClient).Credentials = new-object System.Net.NetworkCredential($username, $password, $domain)).DownloadString($url))

