< Back
Watch-DbaDbLogin
Post
NAME Watch-DbaDbLogin
SYNOPSIS
Tracks SQL Server logins: which host they came from, what database they're using, and what program is being used
to log in.
SYNTAX
Watch-DbaDbLogin [-SqlInstance] <DbaInstanceParameter> [[-Database] <System.Object>] [[-Table] <String>]
[[-SqlCredential] <Pscredential>] [[-SqlCms] <String>] [[-ServersFromFile] <String>] [-EnableException <Switch>]
[<CommonParameters>]
DESCRIPTION
Watch-DbaDbLogin uses SQL Server DMV's to track logins into a SQL Server table. This is helpful when you need to
migrate a SQL Server and update connection strings, but have inadequate documentation on which
servers/applications are logging into your SQL instance.
Running this script every 5 minutes for a week should give you a sufficient idea about database and login usage.
PARAMETERS
-Database [<System.Object>]
The name of the Watch database.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ServersFromFile [<String>]
Specifies a file containing a list of servers to watch. This file must contain one server name per line.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCms [<String>]
Specifies a Central Management Server to query for a list of servers to watch.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -
Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<DbaInstanceParameter>]
The SQL Server that stores the Watch database.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Table [<String>]
The name of the Watch table. By default, this is DbaTools-WatchDbLogins.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Tags: Login
Author: Chrissy LeMaire (@cl), netnerds.net
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
Requires: sysadmin access on all SQL Servers for the most accurate results
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Watch-DbaDbLogin -SqlInstance sqlserver -SqlCms SqlCms1
A list of all database instances within the Central Management Server SqlCms1 is generated. Using this list, the
script enumerates all the processes and gathers login information and saves it to the table Dblogins in the
DatabaseLogins database on SQL Server sqlserver.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Watch-DbaDbLogin -SqlInstance sqlcluster -Database CentralAudit -ServersFromFile .\\sqlservers.txt
A list of servers is gathered from the file sqlservers.txt in the current directory. Using this list, the script
enumerates all the processes and gathers login information and saves it to the table Dblogins in the CentralAudit
database on SQL Server sqlcluster.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Watch-DbaDbLogin -SqlInstance sqlserver -SqlCms SqlCms1 -SqlCredential $cred
A list of servers is generated using database instance names within the SQL2014Clusters group on the Central
Management Server SqlCms1. Using this list, the script enumerates all the processes and gathers login information
and saves it to the table Dblogins in the DatabaseLogins database on sqlserver.
RELATED LINKS
https://dbatools.io/Watch-DbaDbLogin
SYNOPSIS
Tracks SQL Server logins: which host they came from, what database they're using, and what program is being used
to log in.
SYNTAX
Watch-DbaDbLogin [-SqlInstance] <DbaInstanceParameter> [[-Database] <System.Object>] [[-Table] <String>]
[[-SqlCredential] <Pscredential>] [[-SqlCms] <String>] [[-ServersFromFile] <String>] [-EnableException <Switch>]
[<CommonParameters>]
DESCRIPTION
Watch-DbaDbLogin uses SQL Server DMV's to track logins into a SQL Server table. This is helpful when you need to
migrate a SQL Server and update connection strings, but have inadequate documentation on which
servers/applications are logging into your SQL instance.
Running this script every 5 minutes for a week should give you a sufficient idea about database and login usage.
PARAMETERS
-Database [<System.Object>]
The name of the Watch database.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-EnableException [<Switch>]
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.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-ServersFromFile [<String>]
Specifies a file containing a list of servers to watch. This file must contain one server name per line.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCms [<String>]
Specifies a Central Management Server to query for a list of servers to watch.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlCredential [<Pscredential>]
Login to the target instance using alternative credentials. Accepts PowerShell credentials (Get-Credential).
Windows Authentication, SQL Server Authentication, Active Directory - Password, and Active Directory -
Integrated are all supported.
For MFA support, please use Connect-DbaInstance.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-SqlInstance [<DbaInstanceParameter>]
The SQL Server that stores the Watch database.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
-Table [<String>]
The name of the Watch table. By default, this is DbaTools-WatchDbLogins.
Required? false
Position? named
Default value
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
OUTPUTS
NOTES
Tags: Login
Author: Chrissy LeMaire (@cl), netnerds.net
Website: https://dbatools.io
Copyright: (c) 2018 by dbatools, licensed under MIT
License: MIT https://opensource.org/licenses/MIT
Requires: sysadmin access on all SQL Servers for the most accurate results
-------------------------- EXAMPLE 1 --------------------------
PS C:\\>Watch-DbaDbLogin -SqlInstance sqlserver -SqlCms SqlCms1
A list of all database instances within the Central Management Server SqlCms1 is generated. Using this list, the
script enumerates all the processes and gathers login information and saves it to the table Dblogins in the
DatabaseLogins database on SQL Server sqlserver.
-------------------------- EXAMPLE 2 --------------------------
PS C:\\>Watch-DbaDbLogin -SqlInstance sqlcluster -Database CentralAudit -ServersFromFile .\\sqlservers.txt
A list of servers is gathered from the file sqlservers.txt in the current directory. Using this list, the script
enumerates all the processes and gathers login information and saves it to the table Dblogins in the CentralAudit
database on SQL Server sqlcluster.
-------------------------- EXAMPLE 3 --------------------------
PS C:\\>Watch-DbaDbLogin -SqlInstance sqlserver -SqlCms SqlCms1 -SqlCredential $cred
A list of servers is generated using database instance names within the SQL2014Clusters group on the Central
Management Server SqlCms1. Using this list, the script enumerates all the processes and gathers login information
and saves it to the table Dblogins in the DatabaseLogins database on sqlserver.
RELATED LINKS
https://dbatools.io/Watch-DbaDbLogin