Skip to content

Instantly share code, notes, and snippets.

@usshen
Forked from lawrencegripper/invokeWithCookie.ps1
Created February 10, 2021 15:03
Show Gist options
  • Save usshen/2f97a61dce19ffe0c7d3d7f3d820b277 to your computer and use it in GitHub Desktop.
Save usshen/2f97a61dce19ffe0c7d3d7f3d820b277 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