---
title: "Get-DbatoolsError"
description: "Retrieves detailed error information from failed dbatools commands for troubleshooting"
url: "https://dbatools.io/Get-DbatoolsError/"
availability: "Windows, Linux, macOS"
tags: ["Module", "Support"]
author: "Chrissy LeMaire (@cl)"
source: "https://github.com/dataplat/dbatools/blob/master/public/Get-DbatoolsError.ps1"
last_updated: "2024-01-01"
---

# Get-DbatoolsError

## Synopsis

Retrieves detailed error information from failed dbatools commands for troubleshooting

## Description

Retrieves detailed error information specifically from dbatools command failures, filtering the PowerShell error collection to show only dbatools-related errors. This provides comprehensive diagnostic details including exception messages, stack traces, and invocation information that help troubleshoot SQL Server connection issues, permission problems, or command syntax errors. By default, it returns only the most recent dbatools error, but can retrieve all historical dbatools errors for pattern analysis or support requests.

## Syntax

```powershell
Get-DbatoolsError
    [[-First] <Int32>]
    [[-Last] <Int32>]
    [[-Skip] <Int32>]
    [-All]
    [<CommonParameters>]

```

## Examples

### Example 1: Returns detailed error information for the most recent dbatools error

```powershell
PS C:\> Get-DbatoolsError
```

### Example 2: Returns detailed error information for all dbatools-related errors

```powershell
PS C:\> Get-DbatoolsError -All
```

### Example 3: Returns the oldest dbatools-related error in the pipeline

```powershell
PS C:\> Get-DbatoolsError -Last 1
```

### Optional Parameters

##### -First

Specifies the number of most recent dbatools errors to return. Defaults to 1 if no parameters are specified.  
Use this when you need to examine the latest few errors after a batch operation or troubleshooting session.

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

##### -Last

Specifies the number of oldest dbatools errors to return from the error history.  
Use this when you need to see the earliest errors that occurred during a session or to trace the root cause of cascading failures.

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

##### -Skip

Specifies the number of most recent dbatools errors to skip before returning results.  
Use this when you want to ignore the latest error and examine previous errors, or when paging through error history.

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

##### -All

Returns detailed information for all dbatools-related errors in the current PowerShell session.  
Use this when creating support tickets, analyzing error patterns, or performing comprehensive troubleshooting of multiple failed commands.

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

## Outputs

**System.Management.Automation.ErrorRecord**

Returns one or more ErrorRecord objects from the PowerShell global error collection, filtered to show only dbatools-related errors based on the FullyQualifiedErrorId containing "dbatools".

**Properties (selected from ErrorRecord):**

- CategoryInfo: The error category classification (e.g., ConnectionError, PermissionDenied, SyntaxError)
- ErrorDetails: Additional structured error information including message and recommendations
- Exception: The underlying .NET exception that was thrown
- FullyQualifiedErrorId: Fully qualified error identifier used to identify dbatools-related errors
- InvocationInfo: Details about where and how the error occurred in the script (file, line, column, command name)
- PipelineIterationInfo: Information about the position in the pipeline when the error occurred
- PSMessageDetails: Additional PowerShell message details if available
- ScriptStackTrace: Stack trace showing the call hierarchy at the point of the error
- TargetObject: The object that was being processed when the error occurred
All properties from the full ErrorRecord object are available using Select-Object *.

---

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