commands

^

Test-DbaWindowsLogin

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.

Synopsis

Test-DbaWindowsLogin finds any logins on SQL instance that are AD logins with either disabled AD user accounts or ones that no longer exist

Description

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.

Syntax

Test-DbaWindowsLogin
    [[-SqlInstance] <DbaInstanceParameter[]>]
    [[-SqlCredential] <PSCredential>]
    [[-Login] <String[]>]
    [[-ExcludeLogin] <String[]>]
    [[-FilterBy] <String>]
    [[-IgnoreDomains] <String[]>]
    [[-InputObject] <Login[]>]
    [-EnableException]
    [<CommonParameters>]

 

Examples

 

Example: 1
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

Example: 2
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

Example: 3
PS C:\> Test-DbaWindowsLogin -SqlInstance Dev01 -IgnoreDomains testdomain

Tests all Domain logins excluding any that are from the testdomain

Example: 4
PS C:\> Get-DbaLogin -SqlInstance Dev01 -Login DOMAIN\User | Test-DbaWindowsLogin

Tests only the login returned by Get-DbaLogin

Optional Parameters

-SqlInstance

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 False
Pipeline true (ByValue)
Default Value
-SqlCredential

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
-Login

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
-ExcludeLogin

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
-FilterBy

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
-IgnoreDomains

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
-InputObject

Allows piping from Get-DbaLogin.

Alias
Required False
Pipeline true (ByValue)
Default Value
-EnableException

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