Set-based Insert from PoSh to SQL table

  • Hi all,

    I've been trying to find a way to do set-based inserts into a SQL Server.

    As near as I can tell, there are only 2 ways:

    1) convert the data to be inserted to XML, pass that SQL Server, either a sproc or a file;

    2) export to file and BULK INSERT in SQL Server.

    Neither of these are especially appealing.

    Is there not something equivalent to

    $Table.Insert($NewData)

    Save-IntoSQLTable appears to be on the right track, but also seems to want only to work with traces.

    Any ideas?

  • Anything you can do in .NET you can do in PoSH. Lookup Table-valued Parameters, and how to use them to insert sets of data using one in a Stored Procedure. Most if not all of the examples will be in C# or VB.net, but like I said, you can port that code to PoSH. TVPs or the .NET class SqlBulkCopy are the two best ways I know of to insert batches of data from memory directly into SQL Server. If you write the data to disk that opens up all the bulk load methods of course, like bcp, BULK INSERT, SSIS, etc.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Oooooohhh. Me like TVP! 😀

    Thanks opc!

  • USe Chad Miller´s Out-DataTable and Write-DataTable

    it use Bulk Insert.

    $hell your Experience !!![/url]

  • Thanks Laerte!

    Found you a couple of months ago, I appreciate your work.

    I also found these functions last week.

    P

  • Anytime Man 🙂

    $hell your Experience !!![/url]

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply