---
title: "Remove-DbaLogin"
description: "Removes SQL Server logins from target instances"
url: "https://dbatools.io/Remove-DbaLogin/"
availability: "Windows, Linux, macOS"
tags: ["Delete", "Login"]
author: "Chrissy LeMaire (@cl), netnerds.net"
source: "https://github.com/dataplat/dbatools/blob/master/public/Remove-DbaLogin.ps1"
last_updated: "2024-01-01"
---

# Remove-DbaLogin

## Synopsis

Removes SQL Server logins from target instances

## Description

Removes one or more SQL Server logins from specified instances using the SMO Drop() method. This function handles the complete removal process including dependency checks and provides proper error handling when logins cannot be dropped due to existing sessions or database ownership. Use the -Force parameter to automatically terminate active sessions associated with the login before removal, which is useful when cleaning up test environments or decommissioning user accounts.

## Syntax

```powershell
Remove-DbaLogin
    [-SqlCredential <PSCredential>]
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Remove-DbaLogin -SqlInstance <DbaInstanceParameter[]>
    [-SqlCredential <PSCredential>]
    -Login <String[]>
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Remove-DbaLogin
    [-SqlCredential <PSCredential>]
    -InputObject <Login[]>
    [-Force]
    [-EnableException]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

```

## Examples

### Example 1: Prompts then removes the Login mylogin on SQL Server sql2016

```powershell
PS C:\> Remove-DbaLogin -SqlInstance sql2016 -Login mylogin
```

### Example 2: Prompts then removes the Logins mylogin and yourlogin on SQL Server sql2016

```powershell
PS C:\> Remove-DbaLogin -SqlInstance sql2016 -Login mylogin, yourlogin
```

### Example 3: Does not prompt and swiftly removes mylogin on SQL Server sql2016

```powershell
PS C:\> Remove-DbaLogin -SqlInstance sql2016 -Login mylogin -Confirm:$false
```

### Example 4: Removes mylogin on SQL Server server\instance

```powershell
PS C:\> Get-DbaLogin -SqlInstance server\instance -Login yourlogin | Remove-DbaLogin
```

### Required Parameters

##### -SqlInstance

The target SQL Server instance or instances.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | false |
| Default Value |  |

##### -Login

Specifies the SQL Server login names to remove from the target instance. Accepts multiple login names as an array.  
Use this when you know the specific logins to delete, such as when cleaning up test accounts or decommissioned user logins.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | false |
| Default Value |  |

##### -InputObject

Accepts login objects piped from Get-DbaLogin or other dbatools functions that return SQL Server login objects.  
Use this for advanced filtering scenarios or when chaining multiple dbatools commands together in a pipeline.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | True |
| Pipeline | true (ByValue) |
| Default Value |  |

### Optional Parameters

##### -SqlCredential

Allows you to login to servers using alternative credentials.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Force

Automatically terminates any active database connections and sessions associated with the login before attempting removal.  
Use this when you need to forcibly remove logins that have active sessions, common in development environments or during emergency cleanup.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -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.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | False |

##### -WhatIf

Shows what would happen if the command were to run. No actions are actually performed.

| Property | Value |
| --- | --- |
| Alias | wi |
| Required | False |
| Pipeline | false |
| Default Value |  |

##### -Confirm

Prompts you for confirmation before executing any changing operations within the command.

| Property | Value |
| --- | --- |
| Alias | cf |
| Required | False |
| Pipeline | false |
| Default Value |  |

## Outputs

**PSCustomObject**

Returns one object per login processed, whether successfully removed or failed.

**Properties:**

- ComputerName: The computer name of the SQL Server instance
- InstanceName: The SQL Server instance name
- SqlInstance: The full SQL Server instance name (computer\instance)
- Login: The name of the login that was removed
- Status: Either "Dropped" on success or an error message describing the failure

---

Part of [dbatools](https://dbatools.io/), a free and open source PowerShell module for SQL Server administration. Full command index: https://dbatools.io/commands/
