ps/Modules/Alkami.PowerShell.Configuration/Public/Get-NetshExcludedPortRanges.ps1
2023-05-30 22:51:22 -07:00

29 lines
926 B
PowerShell

function Get-NetshExcludedPortRanges {
<#
.SYNOPSIS
Get the existing port ranges and parse them into actionable items
#>
[CmdletBinding()]
[OutputType([object[]])]
param (
)
$ranges = @()
$existingExcludedPortRanges = (netsh int ipv4 show excludedportrange protocol=tcp)
foreach($existingRange in $existingExcludedPortRanges) {
$cleanedRange = $existingRange.Replace('Protocol tcp Port Exclusion Ranges','').Replace('* - Administered port exclusions.','').Replace('Start Port','').Replace('End Port','').Replace('--','').Trim()
if ([string]::IsNullOrWhiteSpace($cleanedRange)) {
continue
}
$splits = $cleanedRange -split '\s+'
if ($splits.Length -gt 1) {
$rangeStart = [int]$splits[0]
$rangeEnd = [int]$splits[1]
$ranges += @{ Start = $rangeStart; End = $rangeEnd;}
}
}
return $ranges
}