powershellpowershell-2.0powershell-3.0

DownloadString with basic auth similar to psget's


Anyone know how I can modify the DownloadString below so I can pass basic auth credentials as well?

I am using the same technique used for PsGet (http://psget.net/) to download my own internal scripts and execute them on the fly. However my server is secured using basic auth. I am having trouble applying the credentials and still executing the line using Invoke-Expression.

I need it in one line as I am executing it using "powershell.exe -Command..."

(new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex


Solution

  • You can't do it in one line (well, unless you wrap it up as a cmdlet), but it is easy enough to supply the required credentials:

    $wc = New-Object System.Net.WebClient
    $wc.Credentials = New-Object System.Net.NetworkCredential "user","pass"
    $wc.DownloadString("http://psget.net/GetPsGet.ps1") | iex