With Invoke-WebRequest, this can be done. The details are that if you assign the return value from the cmdlet to $Response, the return code of the web call is $Response.StatusCode while the main content is $Response.Content. Thank you.
In PowerShell 6, Invoke-RestMethod has a "ReponseHeadersVariable" parameter for this. Unfortunately, it isn't available in 5.1 and earlier, so the workaround as already mentioned is to use Invoke-WebRequest.