PowerShell

Supported OS Windows

Integration version1.0.0

To find out if this integration is available in your organization, see your Datadog Integrations page or ask your organization administrator.

To initiate an exception request to enable this integration for your organization, email support@ddog-gov.com.

Overview

Collect custom metrics from read-only PowerShell Get-* cmdlets on Windows hosts. The integration maps cmdlet output properties to metrics and tags. This lets you monitor Windows and application state exposed through PowerShell.

For security, the integration runs only cmdlets and parameters explicitly permitted in an administrator-owned allowlist.

Minimum Agent version: 7.85.0

Setup

Installation

The PowerShell integration is included in the Datadog Agent package. No additional installation is needed.

Configuration

  1. Create or edit the allowlist at C:\ProgramData\Datadog\protected\powershell_allowlist.yaml to permit the read-only cmdlets and parameters that the Agent may run. See the sample PowerShell allowlist for an example. The allowlist must be owned by Administrators or SYSTEM. The check fails closed if the file is missing, invalid, or owned by another user.

    The following example permits the check to query listening TCP connections and correlate them with running processes:

    version: 1
    allowed_cmdlets:
      Get-NetTCPConnection:
        module: NetTCPIP
        parameters:
          State:
            required: false
            allowed_values:
              - Listen
      Get-Process:
        module: Microsoft.PowerShell.Management
    

    Allowlist options

    OptionTypeRequiredDescription
    versionintegerYesAllowlist schema version. The only supported value is 1.
    allowed_cmdletsmappingYesCmdlets that the check may run. The mapping must contain at least one entry, and each key must be a read-only cmdlet name in the form Get-<Noun>.
    allowed_cmdlets.<cmdlet>.modulestringYesModule that the cmdlet must resolve to at runtime. Use the value returned by (Get-Command <cmdlet>).ModuleName. Use "*" to explicitly skip module validation.
    allowed_cmdlets.<cmdlet>.parametersmappingNoParameters that instances may pass to the cmdlet. Undeclared parameters are rejected. Parameter names may contain letters, numbers, and underscores.
    allowed_cmdlets.<cmdlet>.parameters.<parameter>.requiredbooleanNo; defaults to falseWhether every instance using the cmdlet must include this entry in parameters.
    allowed_cmdlets.<cmdlet>.parameters.<parameter>.allowed_valueslist of stringsConditionalCase-sensitive exact values permitted for the parameter. Boolean and numeric instance values are compared using their string forms. Every declared parameter must define allowed_values or pattern. If both are set, allowed_values is used for validation.
    allowed_cmdlets.<cmdlet>.parameters.<parameter>.patternstringConditionalCase-sensitive Go RE2 expression defining permitted values. The expression is automatically anchored and must match the entire parameter value. RE2 does not support lookaround or backreferences. Every declared parameter must define pattern or allowed_values.

    Unknown options cause the allowlist to be rejected. Cmdlet and parameter names are case-sensitive and must match the instance configuration. The allowlist constrains cmdlets and their parameters; where only removes output rows and does not need an allowlist entry. Cmdlets referenced by tag_queries must also appear in allowed_cmdlets. Tag queries invoke their target cmdlets without parameters, so those cmdlets cannot have any required allowlist parameters. Runtime module validation still applies.

  2. Edit powershell.d/conf.yaml in the conf.d folder at the root of the Agent’s configuration directory. See the sample powershell.d/conf.yaml for all available configuration options.

    The following example submits a constant custom metric for each listening TCP connection whose local address does not match 127.*. It also runs Get-Process and joins OwningProcess from each connection to Id from each process to add a process_name tag:

    instances:
      - cmdlet: Get-NetTCPConnection
        name: powershell
        parameters:
          - [State, Listen]
        where:
          - [LocalAddress, notlike, '127.*']
        tags:
          - connection_state:listen
        metrics:
          - [1, tcp_connection.info, gauge]
        tag_by:
          - LocalAddress AS local_address
          - LocalPort AS local_port
        tag_queries:
          - [OwningProcess, Get-Process, Id, ProcessName AS process_name]
    

    The equivalent PowerShell commands are:

    Get-NetTCPConnection -State Listen |
      Where-Object -Property LocalAddress -NotLike -Value '127.*' |
      Select-Object LocalAddress, LocalPort, OwningProcess
    
    Get-Process |
      Select-Object Id, ProcessName
    

    The parameters option passes allowlisted named arguments directly to the cmdlet, while where filters the returned objects using PowerShell Where-Object semantics before selecting properties. All where entries must match for a row to be retained. The check then joins the results where OwningProcess equals Id.

    This configuration submits powershell.tcp_connection.info. A metric property may be a numeric property returned by the cmdlet or the literal 1 for a constant value. Non-numeric properties can be translated with the metric mapping form described in the sample configuration. Supported metric types are gauge, rate, count, monotonic_count, histogram, and distribution.

  3. Restart the Agent.

Validation

Run the Agent’s status subcommand and look for powershell under the Checks section.

Data Collected

Metrics

The PowerShell integration does not include default metrics. All metrics configured through this integration are forwarded to Datadog as custom metrics, which may impact your billing.

Events

The PowerShell integration does not include any events.

Service Checks

The PowerShell integration does not include any service checks.

Troubleshooting

Need help? Contact Datadog support with an Agent Flare.