0

I am running a PowerShell script(which runs a loop) using XP-cmdshell. I am trying insert the error output into a temp table. My script returns single line warning as well as multiple line errors from PowerShell. The errors are inserted into multiple cells rather than single cell. I know PowerShell returns error in multiple line. Is there a way to accommodate the errors in the single cell and also how to remove CrLf(SQL carriage return and line break) while inserting the error from PowerShell to temp table.

Insert into #ErrorLog Exec master.dbo.xp_cmdshell <My Script>

  • 1
    If you want to remove the line breaks, does this answer your question?[Replace a newline in TSQL](https://stackoverflow.com/a/951705/2029983) – Thom A Jan 13 '21 at 13:08
  • 1
    Can we get some context in regards to a code sample? In could be as simple as `-join ";"`. – Abraham Zinala Jan 13 '21 at 13:11
  • @AbrahamZinala Am using ```Copy-DbaDbTableData``` cmdlet to copy the tables from one server to another. – Siva Nesan Jan 13 '21 at 13:17
  • Just have you script normalize the newlines like `($errorMessage -replace '\r|\n', ' ').Trim()` – Theo Jan 13 '21 at 13:28

0 Answers0