How to do wget with cookies in PowerShell How to do wget with cookies in PowerShell powershell powershell

How to do wget with cookies in PowerShell


Ok so you have two options.

  1. Run wget on Windows.
  2. Set properties on the webclient object toreplicate the functionality set by the wget flags.

The first one is easy, just download the Windows version of wget.

Here is the code for the second one.

$source = "http://site.com/qqq"$destination = "d:\site\qqq" $wc = New-Object System.Net.WebClient# Single Example$wc.Headers.Add([System.Net.HttpRequestHeader]::Cookie, "name=value")# Multi Example$wc.Headers.Add([System.Net.HttpRequestHeader]::Cookie, "name=value; name2=value2"); $wc.DownloadFile($source, $destination)

Look inside your cookies.txt file to get the name value pairs.

I'm not sure how to replicate the -x functionality of wget. Give the above a try and see what it does with the file after downloading.

Note - I can't test this...