# encoding: ascii
# api: powershell
# title: Get # of Web Connections
# description: Uses PerformanceCounter to return the number of connections to web sites on the current machine.
# version: 0.1
# type: function
# author: Lance RobinGeson
# license: CC0
# function: Get-WebServiceConnections
# x-poshcode-id: 1147
# x-archived: 2009-06-07T06:01:05
#
# Note:  For more advanced output, or if you change this to look at rate counters (like bytes per second), consider the use NextSample() instead of NextValue().
#
function Get-WebServiceConnections()
{
  $results = @{}
  $perfmon = new-object System.Diagnostics.PerformanceCounter
  $perfmon.CategoryName = "Web Service"
  $perfmon.CounterName = "Current Connections"

  $cat = new-object System.Diagnostics.PerformanceCounterCategory("Web Service")
  $instances = $cat.GetInstanceNames()

  foreach ($instance in $instances)
  {
    $perfmon.InstanceName = $instance
    $results.Add($instance, $perfmon.NextValue())
  }
  write-output $results
}
