Exporting Error from Erroraction parameter

Hi Gents,

Is there anyway to export the error when i use the parameter Erroraction to anyfile format?

Test-Connection -ComputerName (get-content ‘C:\Users\New Text Document.txt’) -ErrorAction Continue

You can use the -ErrorVariable then use the variable to export to file

Get-Process -Name foo -ErrorAction Continue -ErrorVariable r
$r

Or use built-in $Error variable for getting consolidated errors from all the cmdlets.

$Error.Clear() # Clearing all errors before below expression executes.
Get-Process -Name foo -ErrorAction Continue
Get-Service -Name bla -ErrorAction Continue
$Error | Out-File -FilePath c:\temp\allerrors.txt