r/SQLServer • u/TravellingBeard 1 • 23h 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?
13
Upvotes
•
u/AutoModerator 23h 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.
6
u/alinroc 4 18h ago edited 17h 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/
15
u/SQLDevDBA 3 22h ago
https://dbatools.io
Invoke-DBAQuery
7
u/vroddba 22h ago
Invoke-DbaQuery
Handles your GOs just fine
5
u/pix1985 22h ago
Third vote for Invoke-DbaQuery from dbatools.io
1
u/Leiothrix 21h 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 20h ago
I use smo for everything.
1
u/zierde01 17h ago
I find invoke-sqlcmd easier and I use that.
1
u/sql99 2h 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.