I have a PowerShell 5.0 function which I'm trying to use to return a data table that is used in some downstream activities. However, it seems to return duplicates everytime I place this into a variable as so:
function GetTable {
$tbl = New-Object "System.Data.DataTable"
$tbl.Columns.Add("testNum").DataType = [string]
for($i=0; $i -lt 3; $i++){
$tbl.Rows.Add($i)
}
Write-Host $tbl.Rows.Count
return $tbl
}
$test = GetTable
$test.Rows.Count
This outputs:
3
6
Why does the function duplicate the data when returning the data table?