Search code examples
powershellfile-ioinvoke-webrequest

Invoke-WebRequest POST InFile from remote network chain of events


Invoke-WebRequest -Headers $headers -Method "POST" -Uri $uri -InFile $fileToAttach

In the above web request:

  • $uri points to a public website.
  • $fileToAttach points to a remote file share (Access via VPN).
  • My connection is public internet (home internet), connected to above VPN to access the file share.

When I run this command, does the $fileToAttach download to my PC (in memory?) and then the file is sent to $uri? If not, what is the chain of events that happens?


Solution

  • A quick test with Wireshark showed that Invoke-WebRequest, in order:

    1. Starts a TCP connection to the destination server $uri
    2. Loads the entire -InFile file from the remote server into memory,
    3. Continues with the connection in 1, processing https/auth steps,
    4. Posts the file