OCS A/V Edge servers are somewhat wierd critters.  One interface is load balanced, the other is accessed only by the trusted server list.  The Load Balancer should be able to display the number of connections, but what about the internal interface?  Say, we need to perform maintenance on an A/V Edge Server but want to know when the connections drop below a given threshold?  PowerShell to the rescue:

$mrePerfCounterHash.Add($name, (New-Object System.Diagnostics.PerformanceCounter("A/V Edge - 01 - TCP Counters", "- 001 - Active Sessions", "Public Network Interface", $name)));

One disadvantage is that instantiating these Performance Counter Objects take a lot of time.  This is more than balanced out by the advantage is that these Performance Counter Objects are live - they update in realtime.  Thus, we can take a one-time hit of instantiating all the Performance Counter Objects, then store each as an element in a hashtable.  Afterwards, we can just loop over the entries to get the value(s) we need.

$mrePerfCounterHash. = @{};
$configXml.SelectNodes("//XPath") | %
   
Write-Progress "Creating Perf Counter Object for" $_.name;
   
$mrePerfCounterHash.Add($_.name, (New-Object System.Diagnostics.PerformanceCounter("A/V Edge - 01 - TCP Counters", "- 001 - Active Sessions", "Public Network Interface", $_.name)));
}

$sleep = 30;
while ($true) {
   
$now = Get-Date;
   
$mrePerfCounterHash.Keys | Sort-Object | Select-Object @{
      n
= 'TimeStamp';
      e
= { $now; }
      }, @{
      n
= 'name';
      e
= { $_; }
    }, @{
      n
= 'ActiveSessions';
      e
= { $mrePerfCounterHash[$_].RawValue; }
    }
   
Write-Host "";
   
Write-Progress "At $now sleeping for" "$sleep seconds";
   
Start-Sleep -Seconds $sleep;
}