diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f1c20a..b8415fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,13 @@ This CHANGELOG follows the format listed at [Our CHANGELOG Guidelines ](https:// Which is based on [Keep A Changelog](http://keepachangelog.com/) ## [Unreleased] +### Changes - update tests to favor Pester instead of Ruby (@derekgroh) +### Breaking Changes +- update metrics-windows-network.ps1 -Interface argument handling to work with Interfaces names that contain underscores +### Added +- Add new -ListInterfaces option to metrics-windows-network.ps1 to get a list of valid Network Addresses +- Add new ability to metrics-windows-network.psi to output metrics for all Interfaces if no Interface is specified. ## [3.0.0] - 2019-03-04 ### Security diff --git a/bin/metric-windows-network.ps1 b/bin/metric-windows-network.ps1 index 907ca33..4b7c860 100644 --- a/bin/metric-windows-network.ps1 +++ b/bin/metric-windows-network.ps1 @@ -25,7 +25,8 @@ param( [string[]]$Interfaces, - [switch]$UseFullyQualifiedHostname + [switch]$UseFullyQualifiedHostname, + [switch]$ListInterfaces ) $ThisProcess = Get-Process -Id $pid @@ -40,18 +41,41 @@ if ($UseFullyQualifiedHostname -eq $false) { } $perfCategoryID = Get-PerformanceCounterByID -Name 'Network Interface' +if ($perfCategoryID.Length -eq 0 ) { + Write-Host "perfCategoryID: is Null" + Exit 2 +} $localizedCategoryName = Get-PerformanceCounterLocalName -ID $perfCategoryID for($i = 0; $i -lt $Interfaces.Count; $i+=1) { $tmp = $Interfaces[$i] - $Interfaces[$i] = $tmp.Replace("_"," ") + $Interfaces[$i] = $tmp.Replace(" ","_") } +if ($ListInterfaces -eq $true) { + Write-Host "List of Available Interface Names" + Write-Host "Full Name :: Underscore Modified Name" + Write-Host "-------------------------------------" +} foreach ($ObjNet in (Get-Counter -Counter "\$localizedCategoryName(*)\*").CounterSamples) { + $instanceName=$ObjNet.InstanceName.ToString().Replace(" ","_") + if ($ListInterfaces -eq $true) { + $str = $ObjNet.InstanceName.ToString() + Write-Host "$str :: $instanceName" + Break + } - if ($Interfaces.Contains($ObjNet.InstanceName)) { + $include = $false + if ($Interfaces.Count -eq 0) { + $include = $true + } else { + if ($Interfaces.Contains($instanceName)) { + $include = $true + } + } + if ( $include -eq $true ) { $Measurement = ($ObjNet.Path).Trim("\\") -replace "\\","." -replace " ","_" -replace "[(]","." -replace "[)]","" -replace "[\{\}]","" -replace "[\[\]]","" $Measurement = $Measurement.Remove(0,$Measurement.IndexOf(".")) @@ -72,4 +96,5 @@ foreach ($ObjNet in (Get-Counter -Counter "\$localizedCategoryName(*)\*").Counte } -} \ No newline at end of file +} +