Passing objects to PowerShell functions


I’m trying to pass a SQL adapter object to a PowerShell function but I’m getting this error:

executeQueryAndFillTable : Cannot process argument transformation on
parameter ‘da’. Cannot convert the “System.Object[]” value of type
“System.Object[]” to type “System.Data.SqlClient.SqlDataAdapter”.

Here’s the code


Two things:

First : In PowerShell function should be declare before usage.

Second : The way the function is called.

This is not the right way to call a function in PowerShell. If you call it this way PowerShell thinks you are calling the function with only one parameter which is an array (very important , is the array operator in PowerShell) of two elements of distinct types (the reason why System.Object[] in the error).

The right way is :


Passing objects to PowerShell functions by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply