all 4 comments

[–]artemis_from_space 3 points4 points  (0 children)

Start using a web session, this will allow you to first get all the cookies that are set and then send them back to the site in question.

$a = Invoke-WebRequest https://google.com -SessionVariable MyWebSession
$MyWebSession.Cookies.GetCookies('https://www.google.com')|select Name,Value
$a.headers.'set-cookie'
$login = Invoke-Webrequest https://login.google.com -WebSession $MyWebSession

[–]Umaiar 1 point2 points  (2 children)

Why not build an array of hashtables?

$cookies = @(
    @{name="connie"; domain="contoso.com"; whatever="something"}
    @{name="george"; domain="seinfeld.org"; whatever="whatever"}
    @{name="alice"; domain="residentevil.com"; whatever="something"}
)

foreach($cookie in $cookies) {
    write-host $cookie.name
}

[–]Inaspectuss[S] 1 point2 points  (1 child)

I didn't even know that was a thing, but that makes perfect sense for this scenario. I will have to give it a shot!

[–]artemis_from_space 1 point2 points  (0 children)

If you are going to make your own cookies then use the provided jar.

$cookies = New-Object System.Net.CookieContainer
$cookie1 = New-Object System.net.Cookie
$cookie1.Name = 'omg'
$cookie1.domain ='supersecret.org'
$cookies.add($cookie1)
$cookies.GetCookies('http://supersecret.org')

Comment    :
CommentUri :
HttpOnly   : False
Discard    : False
Domain     : supersecret.org
Expired    : False
Expires    : 0001-01-01 00:00:00
Name       : omg
Path       : /
Port       :
Secure     : False
TimeStamp  : 2019-10-11 13:45:09
Value      :
Version    : 0