This function is a wrapper command around Invoke-SqlCmd2.
It was designed to be more convenient to use in a pipeline and to behave in a way consistent with the rest of our functions.
Runs the sql query ‘SELECT foo FROM bar’ against the instance ‘server\instance’.
Invoke-DbaSqlCmd -SqlInstance server\instance -Query ‘SELECT foo FROM bar’
Runs the sql query ‘SELECT foo FROM bar’ against all instances in the group [GROUPNAME] on the CMS [SERVERNAME].
Get-DbaRegisteredServer -SqlInstance [SERVERNAME] -Group [GROUPNAME] | Invoke-DbaSqlCmd -Query ‘SELECT foo FROM bar’
Runs the sql commands stored in rebuild.sql against the instances “server1”, “server1\nordwind” and “server2”.
“server1”, “server1\nordwind”, “server2” | Invoke-DbaSqlCmd -File “C:\scripts\sql\rebuild.sql”
This command was created by Fred Winmann. You can find Fred on Twitter.