---
title: "Get-DbaDbLogShipError"
description: "Retrieves log shipping error details from msdb to troubleshoot failed backup, copy, and restore operations"
url: "https://dbatools.io/Get-DbaDbLogShipError/"
availability: "Windows, Linux, macOS"
tags: ["LogShipping"]
author: "Sander Stad (@sqlstad), sqlstad.nl"
source: "https://github.com/dataplat/dbatools/blob/master/public/Get-DbaDbLogShipError.ps1"
last_updated: "2024-01-01"
---

# Get-DbaDbLogShipError

## Synopsis

Retrieves log shipping error details from msdb to troubleshoot failed backup, copy, and restore operations

## Description

Queries the log shipping monitor error detail table in msdb to return comprehensive error information when log shipping operations fail.  
Identifies which specific action failed (backup on primary, copy, or restore on secondary) along with session details and error messages.  
Saves time by consolidating error details from both primary and secondary instances into a single view, so you don't have to manually query multiple system tables.  
Essential for troubleshooting log shipping failures and determining whether issues occurred during backup, file copy, or database restore phases.

## Syntax

```powershell
Get-DbaDbLogShipError
    [-SqlInstance] <DbaInstanceParameter[]>
    [[-SqlCredential] <PSCredential>]
    [[-Database] <String[]>]
    [[-ExcludeDatabase] <String[]>]
    [[-Action] <String[]>]
    [[-DateTimeFrom] <DateTime>]
    [[-DateTimeTo] <DateTime>]
    [-Primary]
    [-Secondary]
    [-EnableException]
    [<CommonParameters>]

```

## Examples

### Example 1: Get all the log shipping errors that occurred

```powershell
PS C:\> Get-DbaDbLogShipError -SqlInstance sql1
```

### Example 2: Get the errors that have something to do with the backup of the databases

```powershell
PS C:\> Get-DbaDbLogShipError -SqlInstance sql1 -Action Backup
```

### Example 3: Get the errors that occurred on the secondary instance

```powershell
PS C:\> Get-DbaDbLogShipError -SqlInstance sql1 -Secondary
```

Get the errors that occurred on the secondary instance.  
This will return the copy of the restore actions because those only occur on the secondary instance  

### Example 4: Get the errors that have occurred from &quot;01/05/2018&quot;

```powershell
PS C:\> Get-DbaDbLogShipError -SqlInstance sql1 -DateTimeFrom "01/05/2018"
```

Get the errors that have occurred from "01/05/2018". This can also be of format "yyyy-MM-dd"  

### Example 5: Get the errors that have occurred between &quot;01/05/2018&quot; and &quot;01/07/2018&quot;

```powershell
PS C:\> Get-DbaDbLogShipError -SqlInstance sql1 -Secondary -DateTimeFrom "01/05/2018" -DateTimeTo "2018-01-07"
```

Get the errors that have occurred between "01/05/2018" and "01/07/2018".  
See that is doesn't matter how the date is represented.  

### Required Parameters

##### -SqlInstance

The target SQL Server instance or instances. You must have sysadmin access and server version must be SQL Server version 2000 or greater.

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

### Optional Parameters

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

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

##### -Database

Specifies which databases to include when retrieving log shipping errors. Requires exact database names, not wildcards.  
Use this when troubleshooting specific databases rather than reviewing all log shipped databases on the instance.

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

##### -ExcludeDatabase

Excludes specific databases from the log shipping error results. Requires exact database names, not wildcards.  
Useful when you want to see errors for all databases except certain ones, like excluding test databases from production error reviews.

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

##### -Action

Filters errors by log shipping operation type: Backup (primary), Copy (between servers), or Restore (secondary).  
Use this to isolate which phase of log shipping is failing when troubleshooting multi-step log shipping workflows.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value |  |
| Accepted Values | Backup,Copy,Restore |

##### -DateTimeFrom

Sets the earliest date and time for error records to include in results.  
Essential for focusing on recent failures or analyzing errors that occurred after a specific event or change.

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

##### -DateTimeTo

Sets the latest date and time for error records to include in results.  
Combined with DateTimeFrom, this creates a specific time window for analyzing log shipping failures during maintenance windows or incidents.

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

##### -Primary

Returns only errors from backup operations that occur on the primary server.  
Use this when troubleshooting backup failures or primary-side log shipping issues like insufficient disk space or backup device problems.

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

##### -Secondary

Returns only errors from copy and restore operations that occur on secondary servers.  
Use this when troubleshooting file transfer failures or restore issues on the destination server, such as network connectivity or disk space problems.

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

## Outputs

**PSCustomObject**

Returns one object per log shipping error found. If no errors exist, nothing is returned.

**Properties:**

- ComputerName: The name of the computer hosting the SQL Server instance
- InstanceName: The SQL Server instance name
- SqlInstance: The full SQL Server instance name (computer\instance format)
- Database: Name of the database involved in the log shipping error
- Instance: The role where the error occurred - either "Primary" (backup operation) or "Secondary" (copy or restore operation)
- Action: The type of log shipping operation that failed - "Backup" (primary server), "Copy" (between servers), or "Restore" (secondary server)
- SessionID: Unique identifier for the log shipping session in which the error occurred
- SequenceNumber: Sequential number of this error within the session for ordering multiple errors
- LogTime: DateTime when the error was recorded in the log shipping monitor tables
- Message: The detailed error message describing what went wrong (e.g., file not found, insufficient disk space, network timeout)

---

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