How can I get powershell exception descriptions into a string?

后端 未结 5 1532
猫巷女王i
猫巷女王i 2021-01-04 09:15

I want to have access to the same message that Powershell prints when you send an error record to the output stream

Example:

This is the excep

5条回答
  •  粉色の甜心
    2021-01-04 10:10

    Foreach ($Errors in $Error){
      #Log Eintrag wird zusammengesetzt und in errorlog.txt geschrieben
      "[$Date] $($Errors.CategoryInfo.Category) $($Errors.CategoryInfo.Activity) $($Errors.CategoryInfo.Reason) $($Errors.CategoryInfo.TargetName) $($Errors.CategoryInfo.TargetType) $($Errors.Exception.Message)" |Add-Content $Path\errorlog.txt -Encoding UTF8
    }
    

    You can also do this and you will get all Informations about the Error

提交回复
热议问题