private/test/Test-PortAvailable.ps1
function Test-PortAvailable { [CmdletBinding(PositionalBinding = $true)] [OutputType([bool])] param( [Parameter(Mandatory = $true)] [ValidateRange(1, 65535)] [int] $Port ) Write-Host "Testing port $Port.." -NoNewline -ForegroundColor DarkGray $count = netstat -aon | find `":$Port `" /c $result = ($count -eq 0) if ($result) { Write-Host 'Available.' -ForegroundColor DarkGray } else { Write-Host 'Busy.' -ForegroundColor DarkGray } return $result } |