Author | Stephen Bennett, sqlnotesfromtheunderground.wordpress.com , Chrissy LeMaire (@cl) |
Availability | Windows, Linux, macOS |
Want to see the source code for this command? Check out Test-DbaWindowsLogin on GitHub.
Want to see the Bill Of Health for this command? Check out Test-DbaWindowsLogin.
Test-DbaWindowsLogin finds any logins on SQL instance that are AD logins with either disabled AD user accounts or ones that no longer exist
The purpose of this function is to find SQL Server logins that are used by active directory users that are either disabled or removed from the domain. It allows you to keep your logins accurate and up to date by removing accounts that are no longer needed.
Test-DbaWindowsLogin
[-SqlInstance] <DbaInstanceParameter[]>
[[-SqlCredential] <PSCredential>]
[[-Login] <Object[]>]
[[-ExcludeLogin] <Object[]>]
[[-FilterBy] <String>]
[[-IgnoreDomains] <String[]>]
[-EnableException]
[<CommonParameters>]
PS C:\> Test-DbaWindowsLogin -SqlInstance Dev01
Tests all logins in the current Active Directory domain that are either disabled or do not exist on the SQL Server instance Dev01
PS C:\> Test-DbaWindowsLogin -SqlInstance Dev01 -FilterBy GroupsOnly | Select-Object -Property *
Tests all Active Directory groups that have logins on Dev01, and shows all information for those logins
PS C:\> Test-DbaWindowsLogin -SqlInstance Dev01 -IgnoreDomains testdomain
Tests all Domain logins excluding any that are from the testdomain
The SQL Server instance you're checking logins on. You must have sysadmin access and server version must be SQL Server version 2000 or higher.
Alias | |
Required | True |
Pipeline | true (ByValue) |
Default Value |
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.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies a list of logins to include in the results. Options for this list are auto-populated from the server.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies a list of logins to exclude from the results. Options for this list are auto-populated from the server.
Alias | |
Required | False |
Pipeline | false |
Default Value |
Specifies the object types to return. By default, both Logins and Groups are returned. Valid options for this parameter are 'GroupsOnly' and 'LoginsOnly'.
Alias | |
Required | False |
Pipeline | false |
Default Value | None |
Accepted Values | LoginsOnly,GroupsOnly,None |
Specifies a list of Active Directory domains to ignore. By default, all domains in the forest as well as all trusted domains are traversed.
Alias | |
Required | False |
Pipeline | false |
Default Value |
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 |