Remove‑SqlDscLogin - dsccommunity/SqlServerDsc GitHub Wiki

SYNOPSIS

Removes a SQL Server login.

SYNTAX

ServerObject

Remove-SqlDscLogin -ServerObject <Server> -Name <String> [-KillActiveSessions] [-Force] [-Refresh]
 [-WhatIf] [-Confirm] [<CommonParameters>]

LoginObject

Remove-SqlDscLogin -LoginObject <Login> [-KillActiveSessions] [-Force] 
 [-WhatIf] [-Confirm] [<CommonParameters>]

DESCRIPTION

This command removes a SQL Server login from a SQL Server Database Engine instance.

EXAMPLES

EXAMPLE 1

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$loginObject = $serverObject | Get-SqlDscLogin -Name 'MyLogin'
$loginObject | Remove-SqlDscLogin

Removes the login named MyLogin.

EXAMPLE 2

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Remove-SqlDscLogin -Name 'MyLogin'

Removes the login named MyLogin.

EXAMPLE 3

$serverObject = Connect-SqlDscDatabaseEngine -InstanceName 'MyInstance'
$serverObject | Remove-SqlDscLogin -Name 'MyLogin' -KillActiveSessions -Force

Removes the login named MyLogin after terminating any active sessions for the login.

PARAMETERS

-Force

Specifies that the login should be removed without any confirmation.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-KillActiveSessions

Specifies that any active sessions for the login should be terminated before attempting to drop the login. This is useful when the login has active connections that would otherwise prevent the drop operation.

Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-LoginObject

Specifies a login object to remove.

Type: Login
Parameter Sets: LoginObject
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Name

Specifies the name of the server login to be removed.

Type: String
Parameter Sets: ServerObject
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-Refresh

Specifies that the ServerObject's logins should be refreshed before trying to remove the login object. This is helpful when logins could have been modified outside of the ServerObject, for example through T-SQL. But on instances with a large number of logins it might be better to make sure the ServerObject is recent enough, or pass in LoginObject.

Type: SwitchParameter
Parameter Sets: ServerObject
Aliases:

Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False

-ServerObject

Specifies current server connection object.

Type: Server
Parameter Sets: ServerObject
Aliases:

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False

-Confirm

Prompts you for confirmation before running the cmdlet.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type: SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

Microsoft.SqlServer.Management.Smo.Server

Specifies a server connection object.

Microsoft.SqlServer.Management.Smo.Login

Specifies a login object.

OUTPUTS

None.

NOTES

RELATED LINKS

⚠️ **GitHub.com Fallback** ⚠️