PoshCode Archive  Artifact [f9227e99ab]

Artifact f9227e99ab68280d9f37d371113f5824577ef33902a336cd56d6d2ff0e945597:

  • File Get-of-Web-Connections.ps1 — part of check-in [9a766b0a43] at 2018-06-10 12:56:32 on branch trunk — Uses PerformanceCounter to return the number of connections to web sites on the current machine. (user: Lance RobinGeson size: 1031)

# 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
}