Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd simplify this significantly by using capture groups in your regex and also using the switch condition's ability to process regular expressions. </p> <p>Oh and I'd use a dictionary to ensure that each server is tracked individually while allowing you to access the data after the capture is complete. This would also give you the ability to do some historical tracking and comparison if you saved the data... but that's outside of this scope ;)</p> <p>e.g.</p> <pre><code> $addressesInUse = @{}; $addressesFree = @{}; foreach ($server in $serverList) { $mibinfo = netsh dhcp server \\$server show mibinfo; #| where-object {$_-match "No. of Addresses in use = "} | foreach ($info in $mibinfo) { switch -regex ($info) { "No. of Addresses in use = (?&lt;count&gt;\d+)" { $val = $Matches["count"]; if ($addressesInUse.ContainsKey($server)) { $addressesInUse.Add($server,$val); } else { $scopeCount.$server += $val; } break; } "No. of free Addresses = (?&lt;count&gt;\d+)" { $val = [int]::Parse($Matches["count"]); if ($addressesFree.ContainsKey($server)) { $addressesFree.Add($server,$val); } else { $addressesFree.$server += $val; } break } } } } foreach ($key in $addressesFree.keys) { $total = $addressesInUse.$key + $addressesFree.$key; $percent = [Math]::Round($addressesInUse.$server / $total*100,2) Write-Host ("DHCP availablility for server {0}" -f $key); Write-Host ("No. of Addresses in use = {0}" -f $addressesInUse.$key); Write-Host ("No. of free Addresses = {0}" -f $addressesFree.$key); Write-Host ("Total Addresses: {0}" -f $total); Write-Host ("Percent in use: {0}%" - $percent); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload