Comments on: submitting an issue https://dbatools.io/new-issue/ the community's sql powershell module Fri, 12 Jul 2019 12:49:48 +0000 hourly 1 https://wordpress.org/?v=5.3.4 By: Patrick van Nederepelt https://dbatools.io/new-issue/#comment-68667 Fri, 12 Jul 2019 12:49:48 +0000 https://dbatools.io/?p=6825#comment-68667 Improvement concerning: Write-DbaDbTableData

In this part below the row: “$optionValue = Get-Variable $option -ValueOnly -ErrorAction SilentlyContinue” may result in an extra row tot $error. So I added this code to check if the variable does exists or has a value:
$scriptblockje = [Scriptblock]::Create(“$”+$option)
$retval = Invoke-Command -ScriptBlock $scriptblockje
if ($retval -eq $null -or $retval -eq ”) {continue}
Maybe this is not the most beautiful code, but it works for me… And maybe also for others…
I have added this on a server of a client, but when they update dbatools this extra code will be gone, and is it possible to add this change to the allcommands.ps1 of future versions?

————————————– code from allcommands.ps1 ———————————————

$bulkCopyOptions = 0
$options = “TableLock”, “CheckConstraints”, “FireTriggers”, “KeepIdentity”, “KeepNulls”, “Default”

foreach ($option in $options) {

$scriptblockje = [Scriptblock]::Create(“$”+$option)
$retval = Invoke-Command -ScriptBlock $scriptblockje
if ($retval -eq $null -or $retval -eq ”) {continue}

$optionValue = Get-Variable $option -ValueOnly -ErrorAction SilentlyContinue

if ($option -eq “TableLock” -and (!$NoTableLock)) {
$optionValue = $true
}
if ($optionValue -eq $true) {
$bulkCopyOptions += $([Data.SqlClient.SqlBulkCopyOptions]::$option).value__
}
}

]]>