0
votes

I have a normal PS Function uses System.Data.SqlClient.SqlConnection, System.Data.SqlClient.SqlCommand, System.Data.SqlClient.SqlDataAdapter to query db, then return a System.Data.DataTable object.

It works great so far and now I want to make it remoting because of some purposes.

I found it gets db records successfully when be put in a "Invoke-Command -ComputerName xxx -ScriptBlock {}" block.

But the return value isn't the type of System.Data.DataTable, it has a prefix about deserialized, so I can't get the value of each cell by calling properties/methods like before.

How can I do that?

Convert it to an array/hashtable?

Thank you!

1

1 Answers

0
votes

This is how remoting works--you're always going to get a deserialized object. One way to work around this is to push all of the work to the remote and only return the properties you're interested in.

Another option, I've written an out-datatable function which converts any object into a datatable:

http://poshcode.org/3534