Skip to content

Instantly share code, notes, and snippets.

@marking
Forked from lawrencegripper/invokeWithCookie.ps1
Created March 14, 2016 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marking/d0e0dfff21fe662f0d15 to your computer and use it in GitHub Desktop.
Save marking/d0e0dfff21fe662f0d15 to your computer and use it in GitHub Desktop.
Invoke-webrequest With Cookie
$downloadToPath = "c:\somewhere\on\disk\file.zip"
$remoteFileLocation = "http://somewhere/on/the/internet"
$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession
$cookie = New-Object System.Net.Cookie
$cookie.Name = "cookieName"
$cookie.Value = "valueOfCookie"
$cookie.Domain = "domain.for.cookie.com"
$session.Cookies.Add($cookie);
Invoke-WebRequest $remoteFileLocation -WebSession $session -TimeoutSec 900 -OutFile $downloadToPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment