I would like to scan the batch of my local networks to find all standalone Wi-Fi AP. I'm going to archive this by checking the TCP/80 port. I have 89 networks in the text file. My script is below. The script seems to run but I get no output either to the screen or to any file. I would be very appreciative if someone could tell me what's wrong.
#PSVersion 7.1.3 #-----------------------------------------
function Test-Port() {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline = $true, Mandatory = $true)]
[Alias('tp')]
[string[]]$network,
[int]$port = 80
)
#Begin { Write-Verbose "Scanning network $network"}
Process {
1..254 | ForEach-Object -Parallel -ThrottleLimit 10 {
$ip = "$network.$_"
If ($(Test-netConnection –ComputerName $ip -Port $port -ErrorAction SilentlyContinue).TcpTestSucceeded ) {
Write-Output "$ip port $port open" | Out-File "C:\tmp\$network.txt"
}
}
}
}
[string[]]$lans = Get-Content -Path "C:\tmp\lans.txt"
#$lans | Test-Port
Test-Port -network $lans
====== Even this doesn't work with -Parallel. It just doesn't see the $n.
[string[]]$networks = Get-Content -Path "C:\tmp\lans.txt"
[string[]]$a = 1..50
foreach ($n in $networks) {
ForEach-Object -InputObject ($a) -parallel {
write-output $n
} }
And it works fine without -parallel
$lanspopulated?