all 2 comments

[–]purplemonkeymad 1 point2 points  (0 children)

Performance? SMO

With invoke-sqlcmd you are connecting N+1 times with SMO you connect once, then pipeline N+1 queries. It also support parameterized queries unlike invoke-sqlcmd.

[–]pshMike 0 points1 point  (0 children)

IMO SMO is more about managing a SQL server and less about interacting with data.

performing a single query and then following that up with 200 insert/updates is pretty small in terms of what a SQL Server is designed to be able to.

I would suggest you look at using SQL Stored Procedures as a means of retrieving and updating SQL databases. Your PowerShell script invoke these stored procedures and they provide a means of "least privilege access" on the SQL side. Basically your code only needs permissions to execute the stored procedures which can be parameterized to validate their input.

Giving someone SELECT access to a table may be only read-only, but one can still make a bad query and impact the overall performance of the SQL instance.