I need to create and populate a table on sql server db starting from a powershell array of objects coming from select-object
. I need to create the table with the correct datatypes and fields.
One way that I well know is export-csv
and then invoke-sqlcmd
with BULK INSERT
, but I prefer to skip csv export.
How invoke-sqlcmd
is normally used to create/populate a table starting from array of hash tables?
Do you know other ways doing the same job without using invoke-sqlcmd
? Do I need to use System.Data
? How to?
Thanks
EDIT 1: Another possible way is New-Object System.Data.SqlClient.SqlConnection
by which I could ExecuteNonQuery()
for each array element.
EDIT 2: Another option, always based on System.Data
, is update a SqlDataAdapter
instance.