Connecting to SQL instances

You can create a persistent SQL connection using the Get-SqlInstance command. It will return server objects, which provide a great deal of information on instance-level configuration and state. These can also be used as session objects, avoiding the need to create a new connection each time.

To connect to an instance, use it as follows:

$server = Get-SqlInstance -ServerInstance sql2017

Using those as input for commands will lead them to reuse the connection, improving execution performance. See the following example:

$server | Get-SqlAgent
Since parameterization is not uniform across all commands in the module, this example does not cover all uses. The examples in each command's help should still be consulted in case of trouble.
While reusing connections is great for performance, the SqlServer module's commands in most instances do not refresh data once retrieved. Do not reuse a session object for too long at a time. Discard and reconnect.

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

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