July 2018
Beginner
552 pages
13h 18m
English
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
Read now
Unlock full access