r/SQLServer • u/TravellingBeard 1 • 5d ago
Question Your personal preference in PowerShell to run SQL files: invoke-sqlcmd or system.data.sqlclient.connection?
Edit: I really need to preface these types of questions with "I'm not allowed to download DbaTools, I work in a bank that's paranoid about everything."
I enjoy the robustness and finer control of sqlclient.connection, but if my SQL files have GO statements, it's useless unless I did some scrubbing of the script at I load it.
Whereas invoke-sqlcmd is straight and to the point and even if I had 1000 GO's, it will work.
Thoughts?
16
Upvotes
•
u/AutoModerator 5d ago
After your question has been solved /u/TravellingBeard, please reply to the helpful user's comment with the phrase "Solution verified".
This will not only award a point to the contributor for their assistance but also update the post's flair to "Solved".
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
7
u/alinroc 4 5d ago edited 5d ago
Then your infosec team is actively getting in the way of the organization doing work. Do they block all modules, or just the ones they feel like blocking?
https://dbatools.io/secure/
20
u/SQLDevDBA 3 5d ago
https://dbatools.io
Invoke-DBAQuery
8
u/vroddba 5d ago
Invoke-DbaQuery
Handles your GOs just fine
5
u/pix1985 5d ago
Third vote for Invoke-DbaQuery from dbatools.io
1
u/sql99 4d ago
Whoever is telling you to use invoke-dbaquery from dbatools has obviously never used it for advanced scripts, jobs, sqlcmd, variables, etc. Use invoke-sqlcmd >> Invoke-dbaquery.
1
u/Leiothrix 5d ago
I just parse the script and execute each segment separately. It is pretty easy to find a GO statement on its own.
1
u/Dry_Duck3011 5d ago
I use smo for everything.
1
u/zierde01 5d ago
I find invoke-sqlcmd easier and I use that.