Author | Scott Sutherland, 2018 NetSPI , Friedrich Weinmann (@FredWeinmann) |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Find-DbaInstance on GitHub.
Want to see the Bill Of Health for this command? Check out Find-DbaInstance.
Search for SQL Server Instances.
This function searches for SQL Server Instances.
It supports a variety of scans for this purpose which can be separated in two categories:
Discovery:
This is where it compiles a list of computers / addresses to check.
It supports several methods of generating such lists (including Active Directory lookup or IP Ranges), but also supports specifying a list of computers to check.
Scan:
Once a list of computers has been provided, this command will execute a variety of actions to determine any instances present for each of them.
This is described in more detail in the documentation on the '-ScanType' parameter.
Additional parameters allow more granular control over individual scans (e.g. Credentials to use).
Note on logging and auditing:
The Discovery phase is un-problematic since it is non-intrusive, however during the scan phase, all targeted computers may be accessed repeatedly.
This may cause issues with security teams, due to many logon events and possibly failed authentication.
This action constitutes a network scan, which may be illegal depending on the nation you are in and whether you own the network you scan.
If you are unsure whether you may use this command in your environment, check the detailed description on the '-ScanType' parameter and contact your IT security team for advice.
Find-DbaInstance
[-Credential <PSCredential>]
[-SqlCredential <PSCredential>]
[-ScanType {TCPPort | SqlConnect | SqlService | DNSResolve | SPN | Browser | Ping | Default | All}]
[-DomainController <String>]
[-TCPPort <Int32[]>]
[-MinimumConfidence {None | Low | Medium | High}]
[-EnableException]
[<CommonParameters>]
Find-DbaInstance -ComputerName <DbaInstanceParameter[]>
[-Credential <PSCredential>]
[-SqlCredential <PSCredential>]
[-ScanType {TCPPort | SqlConnect | SqlService | DNSResolve | SPN | Browser | Ping | Default | All}]
[-DomainController <String>]
[-TCPPort <Int32[]>]
[-MinimumConfidence {None | Low | Medium | High}]
[-EnableException]
[<CommonParameters>]
Find-DbaInstance -DiscoveryType {IPRange | DomainSPN | Domain | DataSourceEnumeration | DomainServer | All}
[-Credential <PSCredential>]
[-SqlCredential <PSCredential>]
[-ScanType {TCPPort | SqlConnect | SqlService | DNSResolve | SPN | Browser | Ping | Default | All}]
[-IpAddress <String[]>]
[-DomainController <String>]
[-TCPPort <Int32[]>]
[-MinimumConfidence {None | Low | Medium | High}]
[-EnableException]
[<CommonParameters>]
PS C:\> Find-DbaInstance -DiscoveryType Domain, DataSourceEnumeration
Performs a network search for SQL Instances by:
PS C:\> Find-DbaInstance -DiscoveryType All
Performs a network search for SQL Instances, using all discovery protocols:
PS C:\> Get-ADComputer -Filter "*" | Find-DbaInstance
Scans all computers in the domain for SQL Instances, using a deep probe:
PS C:\> Get-Content .\servers.txt | Find-DbaInstance -SqlCredential $cred -ScanType Browser, SqlConnect
Reads all servers from the servers.txt file (one server per line),
then scans each of them for instances using the browser service
and finally attempts to connect to each instance found using the specified credentials.
then scans each of them for instances using the browser service and SqlService
PS C:\> Find-DbaInstance -ComputerName localhost | Get-DbaDatabase | Format-Table -Wrap
Scans localhost for instances using the browser service, traverses all instances for all databases and displays all information in a formatted table.
PS C:\> $databases = Find-DbaInstance -ComputerName localhost | Get-DbaDatabase
PS C:\> $results = $databases | Select-Object SqlInstance, Name, Status, RecoveryModel, SizeMB, Compatibility, Owner, LastFullBackup, LastDiffBackup, LastLogBackup
PS C:\> $results | Format-Table -Wrap
Scans localhost for instances using the browser service, traverses all instances for all databases and displays a subset of the important information in a formatted table.
Using this method regularly is not recommended. Use Get-DbaService or Get-DbaRegServer instead.
The computer to scan. Can be a variety of input types, including text or the output of Get-ADComputer.
Any extra instance information (such as connection strings or live sql server connections) beyond the computername will be discarded.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
The mechanisms to be used to discover instances.
Supports any combination of:
SPN Lookup
The function tries to connect active directory to look up all computers with registered SQL Instances.
Not all instances need to be registered properly, making this not 100% reliable.
By default, your nearest Domain Controller is contacted for this scan.
However it is possible to explicitly state the DC to contact using its DistinguishedName and the '-DomainController' parameter.
If credentials were specified using the '-Credential' parameter, those same credentials are used to perform this lookup, allowing the scan of other domains.
SQL Instance Enumeration
This uses the default UDP Broadcast based instance enumeration used by SSMS to detect instances.
Note that the result from this is not used in the actual scan, but only to compile a list of computers to scan.
To enable the same results for the scan, ensure that the 'Browser' scan is enabled.
IP Address range:
This 'Discovery' uses a range of IPAddresses and simply passes them on to be tested.
See the 'Description' part of help on security issues of network scanning.
By default, it will enumerate all ethernet network adapters on the local computer and scan the entire subnet they are on.
By using the '-IpAddress' parameter, custom network ranges can be specified.
Domain Server:
This will discover every single computer in Active Directory that is a Windows Server and enabled.
By default, your nearest Domain Controller is contacted for this scan.
However it is possible to explicitly state the DC to contact using its DistinguishedName and the '-DomainController' parameter.
If credentials were specified using the '-Credential' parameter, those same credentials are used to perform this lookup, allowing the scan of other domains.
Alias | |
Required | True |
Pipeline | false |
Default Value |
The credentials to use on windows network connection.
These credentials are used for:
Alias | |
Required | False |
Pipeline | false |
Default Value |
The credentials used to connect to SqlInstances to during the scan phase.
See the '-ScanType' parameter documentation on affected scans.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The scans are the individual methods used to retrieve information about the scanned computer and any potentially installed instances.
This parameter is optional, by default all scans except for establishing an actual SQL connection are performed.
Scans can be specified in any arbitrary combination, however at least one instance detecting scan needs to be specified in order for data to be returned.
Scans:
Alias | |
Required | False |
Pipeline | false |
Default Value | Default |
Accepted Values | Default,SQLService,Browser,TCPPort,All,SPN,Ping,SqlConnect,DNSResolve |
This parameter can be used to override the defaults for the IPRange discovery.
This parameter accepts a list of strings supporting any combination of:
Alias | |
Required | False |
Pipeline | false |
Default Value |
The domain controller to contact for SPN lookups / searches.
Uses the credentials from the '-Credential' parameter if specified.
Alias | |
Required | False |
Pipeline | false |
Default Value |
The ports to scan in the TCP Port Scan method.
Defaults to 1433.
Alias | |
Required | False |
Pipeline | false |
Default Value | 1433 |
This command tries to discover instances, which isn't always a sure thing.
Depending on the number and type of scans completed, we have different levels of confidence in our results.
By default, we will return anything that we have at least a low confidence of being an instance.
These are the confidence levels we support and how they are determined:
Alias | |
Required | False |
Pipeline | false |
Default Value | Low |
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch.
Alias | |
Required | False |
Pipeline | false |
Default Value | False |