Is there any way I can utilize this piece of code with Test-NetConnection -ComputerName $_ -Port 5985 instead of Test-Connection -ComputerName $_ -Count 1 -AsJob ? I can't utilize -AsJob with the Test-NetConnection cmdlet. Are there any workarounds?
Here is my code:
$online = @()
$pc = Get-Content C:\servers.txt 
$pc | ForEach-Object { 
    Test-Connection -ComputerName $_ -Count 1 -AsJob 
} | Get-Job | Receive-Job -Wait | 
Select-Object @{Name='ComputerName';Expression={$_.Address}},@{Name='Reachable';Expression={
    if ($_.StatusCode -eq 0) { 
        $true 
    } else { 
        $false 
    }
}} | ForEach-Object {
    if ($_.Reachable -eq $true) {
        $online += $_.ComputerName
    }
}
$online | ft -AutoSize
servers.txt just basically has hostnames of all the machines on the network.