r/SQLServer • u/TravellingBeard 1 • 14h 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?
11
Upvotes
•
u/AutoModerator 14h 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.
5
u/alinroc 4 10h ago edited 9h 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 14h ago
https://dbatools.io
Invoke-DBAQuery
7
u/vroddba 14h ago
Invoke-DbaQuery
Handles your GOs just fine
5
u/pix1985 14h ago
Third vote for Invoke-DbaQuery from dbatools.io
1
u/Leiothrix 13h 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 12h ago
I use smo for everything.
1
u/zierde01 9h ago
I find invoke-sqlcmd easier and I use that.