How to retrieve cookies in PowerShell?

I would like to know on how to retrieve cookies on sample 2.

Sample 1

$URL = Invoke-WebRequest http://www.google.com
$URL.BaseResponse.Cookies

Sample 2

$URL = “http://www.google.com
(Invoke-WebRequest -Uri $URL -SessionVariable Y -UseBasicParsing).Content | Out-File -FilePath C:\TEMP.txt
$URL.baseresponse.cookies, which show nothing

Does anyone have any suggestions?
Thanks in advance for any suggestions

$y would include session state information, including cookies. Probably encoded.

Also, if no cookies were passed, there won’t be any.

On sample 1, cookies is created through Invoke-WebRequest.
On sample 2, cookies should also be created, but when I input following commands, which return nothing.
$URL.BaseResponse.Cookies
$Y.BaseResponse.Cookies
I would like to know any difference on how cookies are handled on sample 2 comparing with sample 1 and how to retrieve cookies under this situation for sample 2.
Do you have any suggestions?
Thank you very much for any suggestions (^v^)

In sample 2 $url is just the string containing the URL you’re accessing so will have no knowledge of cookies

$Y.cookis contains some information but not sure how to drill down into the actual cookies

On web-server side, I would like to know on how server looks at both following requests.
On the other words, do server make a connection log (successful) for both following requests?
Cookies is found for sample 1, but cookies is unknown for sample 2.

  1. $URL = Invoke-WebRequest http://www.google.com
  2. (Invoke-WebRequest -Uri $URL -SessionVariable Y -UseBasicParsing).Content | Out-File -FilePath C:\TEMP.txt

Do you have any suggestions on any difference on web connection from server side?
Thanks, to everyone very much for any suggestions (^v^)