0

I have an object array that I retrieved from the Invoke-SQLCmd. Now I want to replace all the newlines in the AboutPart column.

Here is the code.

$rows = Invoke-SQLCmd -ServerInstance $Server -Database $Database -inputfile "$queriespath\select_WHIProducts.sql" 
foreach($row in $rows) {
    if($row.AboutPart) {
        $row.aboutpart.gettype()
        $row.AboutPart = $row.AboutPart.replace("`r`n",' ')
    }
}

This works, however I am getting errors saying dbnull does not contain a method replace. I've done a check before the replace call and the nulls are still getting through according to the getType() call.

Tomalak
  • 332,285
  • 67
  • 532
  • 628
Patrick Mahoney
  • 95
  • 1
  • 3
  • 9

0 Answers0