Discovering SQL instances

One of the tasks you generally have to perform when assuming a new post as dba, is to figure out what SQL instances are running in your estate. Even if documentation exists, it is often optimistic to rely on it being complete.

Searching for instances can be time-consuming, and there are plenty of commercial tools out there to help just with that. dbatools also provides a tool for just this task: Find-DbaInstance. It operates in two phases, as follows:

  • Phase 1: Discovering computers that might operate MSSQL instances
  • Phase 2: Scanning each potential target found

Not every method is applicable in every environment—you can do a full network sweep port scan with it, which might actually be illegal in your network—and some can significantly slow down performance. Some scans will directly try to connect to management services on the discovered computer (which might pop up in security events and cause some pointed questions from possibly not-so-friendly people).

The various tools applied in Phase 2 are used to create as much confidence in the results as possible, because, depending on the scans you are allowed to perform, you might still end up with a maybe answer. See the following code:

Find-DbaInstance -DiscoveryType Domain,DataSourceEnumeration

This is a mostly sane scan and should be the default discovery call. It will use UDP broadcasts to provoke replies from SQL servers in the local network and scan the Active Directory for registered instances. Then it will try to determine, for each machine found, whether it is a legitimate instance:

Find-DbaInstance -DiscoveryType All

In addition to the previous call, this will also perform a ping sweep of all IP addresses in the local subnet and scan each responding machine. This will take a lot of time, and might get you into legal trouble for scanning networks.

You can specify which scans to perform using the -ScanType parameter. You can also specify alternative credentials to use on connection attempts.

Finally, it is also possible to specify a list of computers to scan, rather than running discovery. The following example also uses the ActiveDirectory module, and will scan all computers in the Active Directory for SQL instances:

Get-ADComputer -Filter "*" | Find-DbaInstance
..................Content has been hidden....................

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