diff --git a/functions/ConvertTo-DbaDataTable.ps1 b/functions/ConvertTo-DbaDataTable.ps1 index b8dc937b5c..306af54150 100644 --- a/functions/ConvertTo-DbaDataTable.ps1 +++ b/functions/ConvertTo-DbaDataTable.ps1 @@ -374,10 +374,18 @@ function ConvertTo-DbaDataTable { $datarow.Item($property.Name) = $newColumn.Value } catch { - Write-Message -Level Warning -Message "Failed to add property $($property.Name) from $object" -ErrorRecord $_ -Target $object + if ($EnableException) { + Stop-Function -Message "Failed to add property $($property.Name) from $object" -ErrorRecord $_ -Target $object + } else { + Write-Message -Level $levl -Message "Failed to add property $($property.Name) from $object" -ErrorRecord $_ -Target $object + } } } else { - Write-Message -Level Warning -Message "Failed to add property $($property.Name) from $object" -ErrorRecord $_ -Target $object + if ($EnableException) { + Stop-Function -Message "Failed to add property $($property.Name) from $object" -ErrorRecord $_ -Target $object + } else { + Write-Message -Level $levl -Message "Failed to add property $($property.Name) from $object" -ErrorRecord $_ -Target $object + } } } }