Catching FULL exception message

前端 未结 5 1892
悲&欢浪女
悲&欢浪女 2020-11-28 21:33

Consider:

Invoke-WebRequest $sumoApiURL -Headers @{\"Content-Type\"= \"application/json\"} -Credential $cred -WebSession $webRequestSession -Method post -Bod         


        
5条回答
  •  庸人自扰
    2020-11-28 22:16

    The following worked well for me

    try {
        asdf
    } catch {
        $string_err = $_ | Out-String
    }
    
    write-host $string_err
    

    The result of this is the following as a string instead of an ErrorRecord object

    asdf : The term 'asdf' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At C:\Users\TASaif\Desktop\tmp\catch_exceptions.ps1:2 char:5
    +     asdf
    +     ~~~~
        + CategoryInfo          : ObjectNotFound: (asdf:String) [], CommandNotFoundException
        + FullyQualifiedErrorId : CommandNotFoundException
    

提交回复
热议问题