Querying and filtering MSFT_NetTCPConnection through WMI with extensions v2

You could make the query more manageable by trimming down the query down to just the required properties with something like:

Get-WmiObject -Query "SELECT Name, OwningProcess, LocalPort FROM MSFT_NetTCPConnection where localport=443" -namespace "root\StandardCIMV2"

But unfortunately piping to Group-Object to get a total is not supported by the data source.

Have you looked at the metrics provided by:

Get-WmiObject -query "SELECT ConnectionsActive, ConnectionsEstablished, ConnectionFailures, ConnectionsPassive, ConnectionsReset FROM Win32_PerfFormattedData_Tcpip_TCPv4"

They may not be fine grain enough for what you need though. If they work, they are counter metrics so you need to handle them as such:

metrics:
    - key: com.dynatrace.extension.host-observability.network.tcp.connections.active
      value: column:ConnectionsActive
      type: count