Querying My Named Instance in PoSh–#SQLNewBlogger

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

I was looking at some sample code the other day and it looked like this.

cd sqlserver:\sql\localhost\default\databases

This allows you to browse the list of databases on your local instance. However, this is for a default instance, which I don’t have on this host. How can I get to a named instance? Usually I connect as .\SQL2016, so where does that fit in PowerShell?

The format you see above is for the SQLServer provider, which is provided as part of the SQLServer PoSh module (or SQLPS if you haven’t adopted the new cmdlets).

If I start at the SQLServer:\ node, I see this:

2017-01-03 15_31_37-powershell

Let’s drop into the SQL node and see that.

2017-01-03 15_32_32-powershell

At this point, I see my localhost and my local computer name. These are really the same thing. We can see that by querying each of them.

2017-01-03 15_33_12-powershell

In my case, I like to type fewer characters, so I’ll look at the Plato node. If I change here, I can also change to an instance, as shown here.

2017-01-03 15_34_21-powershell

Now I can see the databases by changing to that path and getting the directory.

2017-01-03 15_34_31-powershell

Thus, we can see that to query an instance, we use this path:

SQLServer:\SQL\Host\instance

If you want to use the default instance, then use “default”.

A simple query path, but one that some people might wonder about, substituting the named instance for localhost, and not realizing that “Default” means just the default instance.

About way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , , . Bookmark the permalink.