Running manual queries

The SqlServer module provides a dedicated command to run SQL commands against an instance, called Invoke-Sqlcmd. See the following example:

Invoke-Sqlcmd -ServerInstance "sql2017" -Query "SELECT 1 AS Value;"

This will execute a basic query against the default instance on sql2017. The -ServerInstance parameter accepts names, IP addresses, or connection strings.

Specifying a connection string will force the command into using the Named Pipe protocol, locally or over TCP. Servers that have Named Pipes connections disabled cannot be contacted in this way. At the time of writing, the command will ignore protocol-specific settings within the connection string.

It also handles instance server objects, as shown on the previous page. Since SQL commands are always run against the server directly, this command is not affected by stale data being cached. Thus, it is safe to reuse even old connections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.79.59