How to retrieve cookies in PowerShell?

This topic contains 4 replies, has 3 voices, and was last updated by  oemPower 3 months ago.

  • Author
  • #94381


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

    Sample 1

    $URL = Invoke-WebRequest

    Sample 2

    $URL = ""
    (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

  • #94384

    Don Jones

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

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

  • #94386


    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.
    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^)

  • #94497

    Richard Siddaway

    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

  • #94500


    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
    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^)

You must be logged in to reply to this topic.