Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Last active January 18, 2020 00:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IISResetMe/2b907a20d8654032efb2d0d419c3cf6b to your computer and use it in GitHub Desktop.
Save IISResetMe/2b907a20d8654032efb2d0d419c3cf6b to your computer and use it in GitHub Desktop.
function Get-WebExceptionBody
{
param(
[int]$Last
)
if(-not $PSBoundParameters.ContainsKey('Last')){
$Last = 1
}
$ex = $Error |? { $_.Exception -is [System.Net.WebException]} |Select -First $Last
if($ex){
$resp = $ex.Exception.Response
$respstream = $resp.GetResponseStream()
$respstream.Position = 0
[System.IO.StreamReader]::new($respstream).ReadToEnd()
$respstream.Dispose()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment