---
title: "Get-DbaPfAvailableCounter"
description: "Retrieves all Windows performance counters available on local or remote machines for monitoring setup."
url: "https://dbatools.io/Get-DbaPfAvailableCounter/"
availability: "Windows only"
tags: ["Performance", "DataCollector", "PerfCounter"]
author: "Chrissy LeMaire (@cl), netnerds.net"
source: "https://github.com/dataplat/dbatools/blob/master/public/Get-DbaPfAvailableCounter.ps1"
last_updated: "2024-01-01"
---

# Get-DbaPfAvailableCounter

## Synopsis

Retrieves all Windows performance counters available on local or remote machines for monitoring setup.

## Description

Retrieves all Windows performance counters available on specified machines by reading directly from the registry for fast enumeration. This is essential when setting up SQL Server monitoring because you need to know which specific counters are available before configuring data collectors or performance monitoring solutions. The function uses a registry-based approach that's much faster than traditional Get-Counter methods, making it practical for discovering hundreds of available counters across multiple servers. When credentials are provided, they're included in the output for easy piping to other dbatools commands like Add-DbaPfDataCollectorCounter.  
  
Thanks to Daniel Streefkerk for this super fast way of counters  
https://daniel.streefkerkonline.com/2016/02/18/use-powershell-to-list-all-windows-performance-counters-and-their-numeric-ids

## Syntax

```powershell
Get-DbaPfAvailableCounter
    [[-ComputerName] <DbaInstanceParameter[]>]
    [[-Credential] <PSCredential>]
    [[-Pattern] <String>]
    [-EnableException]
    [<CommonParameters>]

```

## Examples

### Example 1: Gets all available counters on the local machine

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

### Example 2: Gets all counters matching sql on the local machine

```powershell
PS C:\> Get-DbaPfAvailableCounter -Pattern *sql*
```

### Example 3: Gets all counters matching sql on the remote server sql2017

```powershell
PS C:\> Get-DbaPfAvailableCounter -ComputerName sql2017 -Pattern *sql*
```

### Example 4: Gets all counters matching sql on the local machine

```powershell
PS C:\> Get-DbaPfAvailableCounter -Pattern *sql*
```

### Example 5: Adds all counters matching &quot;sql&quot; to the DataCollector01 within the &#39;Test Collector Set&#39; CollectorSet

```powershell
PS C:\> Get-DbaPfAvailableCounter -Pattern *sql* | Add-DbaPfDataCollectorCounter -CollectorSet 'Test Collector Set' -Collector DataCollector01
```

### Optional Parameters

##### -ComputerName

Specifies the target computers to query for available performance counters. Defaults to localhost.  
Use this when you need to discover counters on remote SQL Server instances or other servers in your environment before setting up monitoring.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| Default Value | $env:ComputerName |

##### -Credential

Allows you to login to servers using alternative credentials. To use:  
$scred = Get-Credential, then pass $scred object to the -Credential parameter.

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

##### -Pattern

Filters counter names using wildcard pattern matching (supports * and ? wildcards).  
Use this to find specific SQL Server counters like "*sql*" or "*buffer*" when you need to identify relevant performance metrics for monitoring setup.

| Property | Value |
| --- | --- |
| Alias |  |
| Required | False |
| Pipeline | false |
| 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.

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

## Outputs

**PSCustomObject**

Returns one object per available Windows performance counter found on the specified computers.

**Default display properties:**

- ComputerName: The name of the computer where the counter is available
- Name: The performance counter name

**Additional properties available (via Select-Object *):**

- Credential: The PSCredential object used for connecting to the computer; useful for piping to other dbatools commands like Add-DbaPfDataCollectorCounter

---

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