1

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.

madosoft
  • 11
  • 2
  • 1
    `return @($aDfsTgtPath)` -> `return ,$aDfsTgtPath` – user4003407 Nov 11 '15 at 09:33
  • @PetSerAl Now it's ok. Thanks a lot !! Now I'll search to better understand why... – madosoft Nov 11 '15 at 09:42
  • 2
    Possible duplicate of [Pipe complete array-objects instead of array items one at a time?](http://stackoverflow.com/questions/29973212/pipe-complete-array-objects-instead-of-array-items-one-at-a-time) – user4003407 Nov 11 '15 at 09:53

0 Answers0