{"id":7471,"date":"2020-05-12T09:34:05","date_gmt":"2020-05-12T13:34:05","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7471"},"modified":"2021-10-12T10:17:45","modified_gmt":"2021-10-12T14:17:45","slug":"a-powershell-network-monitor","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/","title":{"rendered":"A PowerShell Network Monitor"},"content":{"rendered":"\n<p>I hope you've been trying your hand at the scripting challenges being posted on the <a href=\"https:\/\/ironscripter.us\" target=\"_blank\" rel=\"noopener noreferrer\">Iron Scripter<\/a> website. The challenges are designed for individuals to do on their own to build up their PowerShell scripting skills. A few weeks ago, a challenge was posted to <a href=\"https:\/\/ironscripter.us\/building-a-network-usage-powershell-monitor\/\">create a network monitoring tool<\/a> using PowerShell and the Write-Progress cmdlet. I thought I'd share my notes on the challenge and some of the code I came up with.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Intermediate Challenge<\/h2>\n\n\n\n<p>The first step was to identify the necessary performance counters for Get-Counter.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">$counters = \"\\Network interface(*ethernet*)\\Bytes sent\/sec\",\n\"\\Network interface(*ethernet*)\\Bytes received\/sec\",\n\"\\Network interface(*ethernet*)\\Bytes total\/sec\"<\/code><\/pre>\n\n\n\n<p>With these, I could use Get-Counter to retrieve the data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">\nGet-Counter -Counter $counters -MaxSamples 10 -SampleInterval 1 -ov d | \nSelect-object -ExpandProperty CounterSamples | Select-Object -Property Timestamp,\n@{Name=\"Computername\";Expression = {[regex]::Match($_.path, \"(?&lt;=\\\\\\\\)\\w+\").Value.toUpper() }},\n@{Name = \"Counter\"; Expression = { ($_.path -split \"\\\\\")[-1]}},\n@{Name = \"Network\"; Expression = {$_.instancename}},\n@{Name = \"Count\"; Expression = {$_.cookedValue}}<\/code><\/pre>\n\n\n\n<p id=\"block-6d563340-c17a-4801-ba96-ea938dd86719\">I'm parsing out values from the counter sample property.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1072\" height=\"716\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-1.png\" alt=\"netperf-1\" class=\"wp-image-7472\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-1.png 1072w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-1-300x200.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-1-1024x684.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-1-768x513.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-1-850x568.png 850w\" sizes=\"auto, (max-width: 1072px) 100vw, 1072px\" \/><\/figure>\n\n\n\n<p>If I wanted to take this a step further I could define the output as a custom object and create a format ps1xml file to clean up the display.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Advanced<\/h2>\n\n\n\n<p>The advanced challenge was to create a visual tool using Write-Progress. The cmdlet lets you have multiple progress bars in the same window. You can reference them by an ID number. This meant I had to divide up the counters.<\/p>\n\n\n\n<pre class=\"wp-block-code lang:ps mark:0 decode:true\"><code lang=\"powershell\" class=\"language-powershell\">Get-Counter -Counter $counters -MaxSamples 30 -SampleInterval 1  |\nForEach-Object {\n    $network = $_.countersamples[0].InstanceName\n    $computername = [regex]::Match($_.CounterSamples[0].path, \"(?&lt;=\\\\\\\\)\\w+\").Value.toUpper()\n    $time = $_.timestamp\n    $total = $_.countersamples.where( {$_.path -match \"total\"})\n    $totalKbps = $total.cookedValue*0.008\n    if ($totalKbps -gt 100) {\n        $totalPct = 100\n    }\n    else {\n        $totalPct = $totalKbps\n    }\n    $sent = $_.countersamples.where( {$_.path -match \"sent\"})\n    $sentKbps = $sent.cookedValue*0.008\n    if ($sentKbps -gt 100) {\n        $sentPct = 100\n    }\n    else {\n        $sentPct = $sentKbps\n    }\n    $rcvd = $_.countersamples.where( {$_.path -match \"received\"})\n    $rcvdKbps = $rcvd.cookedValue*0.008\n    if ($rcvdKbps -gt 100) {\n        $rcvdPct = 100\n    }\n    else {\n        $rcvdPct = $rcvdKbps\n    }\n    Write-Progress -Activity \"[$time] $computername : $network\" -status \"Total Kbps $totalKbps\" -id 1 -PercentComplete $totalpct\n    Write-Progress -Activity \" \" -status \"Send Kbps $sentKbps\" -id 2 -PercentComplete $sentpct\n    Write-Progress -Activity \" \" -status \"Received Kbs $rcvdKbps\" -id 3 -PercentComplete $rcvdpct\n\n}\n<\/code><\/pre>\n\n\n\n<p>Another bonus element was to format the data as Kbps.&nbsp; As far as I know, if I multiply the byte value by 0.008 I will get what I want. I also had to take into account the length of the progress bar since it obviously can't go above 100. Thus the display is relative and not a true graph.<\/p>\n\n\n\n<p>In testing this, I found that Write-Progress in Windows PowerShell seems to have a display bug that doesn't produce exactly what I have in mind. But it works just fine in PowerShell 7.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1064\" height=\"544\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2.png\" alt=\"netperf-2\" class=\"wp-image-7473\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2.png 1064w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2-300x153.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2-1024x524.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2-768x393.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2-850x435.png 850w\" sizes=\"auto, (max-width: 1064px) 100vw, 1064px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Get-NetworkPerformance<\/h2>\n\n\n\n<p>I put all of this together into a PowerShell function.<\/p>\n\n\n\n<pre title=\"Get-NetworkPerformance.ps1\" class=\"wp-block-code\"><code lang=\"powershell\" class=\"language-powershell\">Function Get-NetworkPerformance {\n    [cmdletbinding(DefaultParameterSetName = \"sample\")]\n    [alias(\"gnp\")]\n    Param(\n        [Parameter(HelpMessage = \"Specify a computer to connect to.\")]\n        [string]$Computername = $env:computername,\n        [Parameter(HelpMessage = \"Use the network description from Get-NetAdapter\")]\n        [string]$NetworkInterface = \"*ethernet*\",\n        [Parameter(ParameterSetName = \"continuous\")]\n        [switch]$Continuous,\n        [Parameter(Mandatory, ParameterSetName = \"sample\")]\n        [int64]$MaxSamples,\n        [Parameter(Mandatory, ParameterSetName = \"sample\")]\n        [Int32]$SampleInterval,\n        [switch]$Passthru\n    )\n\n    Write-Verbose \"Starting $($MyInvocation.MyCommand)\"\n    Write-Verbose \"Detected parameter set $($pscmdlet.ParameterSetName)\"\n    Write-Verbose \"Validating network interface\"\n    #updated 12 Oct 2021 to make sure only a single network adapter is selected \n    $c = (Get-NetAdapter -InterfaceDescription $NetworkInterface -CimSession $Computername | Where-Object { $_.status -eq 'up' }).count\n    if ($c -gt 1) {\n        Throw \"You must specify a single network interface.\"\n    }\n    Write-Verbose \"Verified a single network interface\"\n    #save the current progressbar setting\n    $bg = $host.PrivateData.progressBackgroundColor\n\n    #the networking counters\n    $counters = \"\\Network interface($NetworkInterface)\\Bytes sent\/sec\",\n    \"\\Network interface($NetworkInterface)\\Bytes received\/sec\",\n    \"\\Network interface($NetworkInterface)\\Bytes total\/sec\"\n\n    $PSBoundParameters.Add(\"counter\", $counters)\n\n    if ($PSBoundParameters.ContainsKey(\"Passthru\")) {\n        [void]( $PSBoundParameters.Remove(\"passthru\"))\n    }\n\n    if ($PSBoundParameters.ContainsKey(\"NetworkInterface\")) {\n        [void]( $PSBoundParameters.Remove(\"NetworkInterface\"))\n    }\n    Write-Verbose \"Passing these parameters to Get-Counter:`n $($PSBoundParameters | Out-String)\"\n\n    Try {\n        Get-Counter @PSBoundParameters -OutVariable pass -ErrorAction Stop |\n        ForEach-Object {\n            $network = $_.countersamples[0].InstanceName\n            $computername = [regex]::Match($_.CounterSamples[0].path, \"(?&lt;=\\\\\\\\)\\w+\").Value.toUpper()\n            $time = $_.timestamp\n            $total = $_.countersamples.where( { $_.path -match \"total\" })\n            $totalKbps = $total.cookedValue * 0.008\n            #adjust the progressbar color\n            if ($totalKbps -ge 150) {\n                $host.PrivateData.progressBackgroundColor = \"Red\"\n            }\n            else {\n                $host.PrivateData.progressBackgroundColor = $bg\n            }\n            if ($totalKbps -gt 100) {\n                $totalPct = 100\n            }\n            else {\n                $totalPct = $totalKbps\n            }\n            $sent = $_.countersamples.where( { $_.path -match \"sent\" })\n            $sentKbps = $sent.cookedValue * 0.008\n            if ($sentKbps -gt 100) {\n                $sentPct = 100\n            }\n            else {\n                $sentPct = $sentKbps\n            }\n            $rcvd = $_.countersamples.where( { $_.path -match \"received\" })\n            $rcvdKbps = $rcvd.cookedValue * 0.008\n            if ($rcvdKbps -gt 100) {\n                $rcvdPct = 100\n            }\n            else {\n                $rcvdPct = $rcvdKbps\n            }\n\n            Write-Progress -Activity \"[$time] $computername : $network\" -Status \"Total Kbps $totalKbps\" -Id 1 -PercentComplete $totalpct\n            Write-Progress -Activity \" \" -Status \"Send Kbps $sentKbps\" -Id 2 -PercentComplete $sentpct\n            Write-Progress -Activity \" \" -Status \"Received Kbs $rcvdKbps\" -Id 3 -PercentComplete $rcvdpct\n        }\n    } #Try\n    Catch {\n        Write-Warning \"Failed to get performance counters. $($_.Exception.message)\"\n    }\n\n    if ($passthru -AND $pass) {\n        Write-Verbose \"Passing results to the pipeline\"\n        $pass\n    }\n\n    #restore the progressbar value\n    $host.PrivateData.progressBackgroundColor = $bg\n    Write-Verbose \"Ending $($MyInvocation.MyCommand)\"\n}<\/code><\/pre>\n\n\n\n<p>The function offers flexibility and ease of use.<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-7474\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-3.png\" alt=\"netperf-3\" width=\"1064\" height=\"544\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-3.png 1064w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-3-300x153.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-3-1024x524.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-3-768x393.png 768w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-3-850x435.png 850w\" sizes=\"auto, (max-width: 1064px) 100vw, 1064px\" \/>The function has room for improvement. For one, there's no error handling. Get-Counter should really be in a Try\/Catch block. This version doesn't handle alternate credentials for remote computers. Nor does it dynamically change the progress background color. I should be able to do that by dynamically changing the value of $host.PrivateData.ProgressBackgroundColor.<\/p>\n\n\n\n<p>I even learned a few new things in solving this challenge, which is really the whole point. I hope you'll try your hand at the challenges. There are tests for every skill level. Good luck.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I hope you&#8217;ve been trying your hand at the scripting challenges being posted on the Iron Scripter website. The challenges are designed for individuals to do on their own to build up their PowerShell scripting skills. A few weeks ago, a challenge was posted to create a network monitoring tool using PowerShell and the Write-Progress&#8230;<\/p>\n","protected":false},"author":1,"featured_media":7473,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New blogness: A #PowerShell Network Monitor ","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,8],"tags":[340,618,627,534,540],"class_list":["post-7471","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell","category-scripting","tag-get-counter","tag-iron-scripter","tag-network","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>A PowerShell Network Monitor &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A PowerShell Network Monitor &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"I hope you&#039;ve been trying your hand at the scripting challenges being posted on the Iron Scripter website. The challenges are designed for individuals to do on their own to build up their PowerShell scripting skills. A few weeks ago, a challenge was posted to create a network monitoring tool using PowerShell and the Write-Progress...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-12T13:34:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-12T14:17:45+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1064\" \/>\n\t<meta property=\"og:image:height\" content=\"544\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"A PowerShell Network Monitor\",\"datePublished\":\"2020-05-12T13:34:05+00:00\",\"dateModified\":\"2021-10-12T14:17:45+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/\"},\"wordCount\":389,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/netperf-2.png\",\"keywords\":[\"Get-Counter\",\"Iron Scripter\",\"Network\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/\",\"name\":\"A PowerShell Network Monitor &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/netperf-2.png\",\"datePublished\":\"2020-05-12T13:34:05+00:00\",\"dateModified\":\"2021-10-12T14:17:45+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/netperf-2.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/05\\\/netperf-2.png\",\"width\":1064,\"height\":544},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7471\\\/a-powershell-network-monitor\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"A PowerShell Network Monitor\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"A PowerShell Network Monitor &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/","og_locale":"en_US","og_type":"article","og_title":"A PowerShell Network Monitor &#8226; The Lonely Administrator","og_description":"I hope you've been trying your hand at the scripting challenges being posted on the Iron Scripter website. The challenges are designed for individuals to do on their own to build up their PowerShell scripting skills. A few weeks ago, a challenge was posted to create a network monitoring tool using PowerShell and the Write-Progress...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/","og_site_name":"The Lonely Administrator","article_published_time":"2020-05-12T13:34:05+00:00","article_modified_time":"2021-10-12T14:17:45+00:00","og_image":[{"width":1064,"height":544,"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2.png","type":"image\/png"}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"A PowerShell Network Monitor","datePublished":"2020-05-12T13:34:05+00:00","dateModified":"2021-10-12T14:17:45+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/"},"wordCount":389,"commentCount":5,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2.png","keywords":["Get-Counter","Iron Scripter","Network","PowerShell","Scripting"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/","name":"A PowerShell Network Monitor &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2.png","datePublished":"2020-05-12T13:34:05+00:00","dateModified":"2021-10-12T14:17:45+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2.png","width":1064,"height":544},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7471\/a-powershell-network-monitor\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"A PowerShell Network Monitor"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/netperf-2.png","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":8107,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8107\/scripting-challenge-meetup\/","url_meta":{"origin":7471,"position":0},"title":"Scripting Challenge Meetup","author":"Jeffery Hicks","date":"February 1, 2021","format":false,"excerpt":"As you probably know, I am the PowerShell problem master behind the challenges from the Iron Scripter site. Solving a PowerShell scripting challenge is a great way to test your skills and expand your knowledge. The final result is merely a means to an end. How you get there and\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/rubik.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1874,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1874\/background-performance-counters\/","url_meta":{"origin":7471,"position":1},"title":"Background Performance Counters","author":"Jeffery Hicks","date":"December 6, 2011","format":false,"excerpt":"Windows Powershell makes it relatively easy to collect performance counter information via the Get-Counter cmdlet. Because I'm assuming you want to collect more than a few seconds of performance information, you'll need to take advantage of PowerShell background jobs if you want your prompt back. Of course, you can always\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/12\/listcounters-300x206.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":9018,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9018\/an-iron-scripter-warm-up-solution\/","url_meta":{"origin":7471,"position":2},"title":"An Iron Scripter Warm-Up Solution","author":"Jeffery Hicks","date":"May 6, 2022","format":false,"excerpt":"We just wrapped up the 2022 edition of the PowerShell+DevOps Global Summit. It was terrific to be with passionate PowerShell professionals again. The culmination of the event is the Iron Scripter Challenge. You can learn more about this year's event and winner here. But there is more to the Iron\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":8143,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8143\/solving-the-powershell-memory-challenge\/","url_meta":{"origin":7471,"position":3},"title":"Solving the PowerShell Memory Challenge","author":"Jeffery Hicks","date":"February 8, 2021","format":false,"excerpt":"I hope you tried your hand at this Iron Scripter PowerShell challenge on reporting memory usage. The basic challenge was to find the total percent of working set memory that a specific process or service is using. Here's how I approached it, with my usual disclaimer that my solution is\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/02\/get-wspct.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":7559,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7559\/an-expanded-powershell-scripting-inventory-tool\/","url_meta":{"origin":7471,"position":4},"title":"An Expanded PowerShell Scripting Inventory Tool","author":"Jeffery Hicks","date":"June 19, 2020","format":false,"excerpt":"The other day I shared my code that I worked up to solve an Iron Scripter PowerShell challenge. One of the shortcomings was that I didn't address a challenge to include a property that would indicate what file was using a given command. I also felt I could do better\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":8236,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8236\/solving-another-powershell-math-challenge\/","url_meta":{"origin":7471,"position":5},"title":"Solving Another PowerShell Math Challenge","author":"Jeffery Hicks","date":"March 22, 2021","format":false,"excerpt":"Last month, the Iron Scripter Chairman posted a \"fun\" PowerShell scripting challenge. Actually, a few math-related challenges . As with all these challenges, the techniques and concepts you use to solve the challenge are more important than the result itself. Here's how I approached the problems. Problem #1 The first\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7471","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=7471"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7471\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media\/7473"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7471"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7471"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}