Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.