January 16, 2014

Subscribe

Pass a table type parameter to sql server via powershell

by Scott Newman

Still don’t like the title, but I’m pushing it anyway. Here is how to pass a DataTable to a Sql Server stored procedure via powershell. In my case, I’m gathering a boat-load of data from the sys.dm_os_performance_counters DMV for numerous server to be queried and reported upon. First I query the target server, get the results into a datareader, load said datareader into a DataTable and then pass the DataTable as a parameter to a stored proc to be saved off. Use at your own risk, this has been only minimally tested.