I'm trying to return an array from a function that query a sql table. All ok but only if the elements of array is more than one. If the array is composed by only one element the function doesn't return a type array but a type string. I'm a newbie to powershell and so confused... Here my function :
Function test2{
$query = @"
SELECT DfsTgtPath
FROM DfsData_v2 WHERE TgtSrvName = 'compname' AND DfsTgtPath LIKE
'%string%' ORDER BY DfsTgtPath"@
$connection = new-object system.data.sqlclient.sqlconnection("server=SQLSERV;database=DB;trusted_connect>i on=true;" )
$adapter = new-object system.data.sqlclient.sqldataadapter ($query,$connection)
$table = new-object system.data.datatable
$recs = $adapter.Fill($table)
$aDfsTgtPath = @($table | select -ExpandProperty DfsTgtPath)
return @($aDfsTgtPath)
}
$result = test2
I would expect the $result as an array containing one single string element but it's seems to be not an array but of type System.String.