From 02faaa461362c22bf2e1f1571b9a4207a51d6052 Mon Sep 17 00:00:00 2001 From: Gianluca Sartori Date: Tue, 5 Feb 2019 17:34:29 +0100 Subject: [PATCH] Added Stop-Function calls to fix #5050 --- functions/ConvertTo-DbaDataTable.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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 + } } } }