So, I have a simple script that's running test-netconnection against a number of different servers and ports, to verify that the SCCM client will have the necessary connectivity. I'm collecting a couple of variables at the start, and I'm static setting a few others because they're not site specific and will be used for all tests.
But the issue is that I want to have a descriptor print out on the screen before each section, followed by the output table, just to make the output easier to read at a glance. But it's not doing that at all, and I have no idea how to get it to do that. So basically I want something like this:
Testing connectivity to the local distribution point
ComputerName RemoteAddress RemotePort TCPTestSucceeded
-------------- ----------- ---------------- ----------------
DPserver 192.168.1.1 80 True
DPserver 192.168.1.1 443 True
Testing Connectivity to the Management Points
ComputerName RemoteAddress RemotePort TCPTestSucceeded
-------------- ----------- ---------------- ----------------
MPserver 192.168.1.1 80 True
MPserver 192.168.1.1 443 True
But instead, I'm getting this (edited to reflect the actual current results, following the change recommended by novice):
Testing connectivity to the local distribution point
Testing connectivity to the management points
ComputerName RemoteAddress RemotePort TcpTestSucceeded
------------ ------------- ---------- ----------------
server1 10.90.82.131 80 True
server1 10.90.82.131 443 True
server1 10.90.82.131 8005 True
server2 10.88.166.167 10123 True
server2 10.88.166.167 80 True
server2 10.88.166.167 443 True
server3 10.88.166.207 10123 True
server3 10.88.166.207 80 True
server3 10.88.166.207 443 True
server4 10.88.167.78 10123 True
server4 10.88.167.78 80 True
server4 10.88.167.78 443 True
Testing connectivity to the software update points
server5 10.88.167.80 80 True
server5 10.88.167.80 8530 True
server5 10.88.167.80 443 False
server5 10.88.167.80 8531 True
server6 10.88.167.81 80 True
server6 10.88.167.81 8530 True
server6 10.88.167.81 443 False
server6 10.88.167.81 8531 True
Part of the issue is that the error is appearing, even though I have -ErrorAction set to SilentlyContinue, and then part of the issue is that the header is only appearing once. I'm guessing I would have to group up the results in some manner to get the header to appear for each group, but I can't figure out how to do that.
Can anyone assist? This is the full script I have right now (with the static server names changed for posting):
$DP = Read-Host -Prompt 'Input the FQDN for the local DP'
$MP1 = 'MP1'
$MP2 = 'MP2'
$MP3 = 'MP3'
$SUP1 = 'SUP1'
$SUP2 = 'SUP2'
$Client = Read-Host -Prompt 'Input the workstation to test from'
Enter-PSSession $Client
Write-Host 'Testing connectivity to the local distribution point'
Test-NetConnection -Port 80 $DP -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 443 $DP -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 8005 $DP -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Write-Host 'Testing connectivity to the management points'
Test-NetConnection -Port 10123 $MP1 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 80 $MP1 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 443 $MP1 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 10123 $MP2 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 80 $MP2 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 443 $MP2 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 10123 $MP3 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 80 $MP3 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 443 $MP3 -Erroraction SilentlyContinue | Select-Object -
Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Write-Host 'Testing connectivity to the software update points'
Test-NetConnection -Port 80 $SUP1 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 8530 $SUP1 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 443 $SUP1 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 8531 $SUP1 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 80 $SUP2 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 8530 $SUP2 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 443 $SUP2 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Test-NetConnection -Port 8531 $SUP2 -Erroraction SilentlyContinue | Select-Object -Property ComputerName,RemoteAddress,RemotePort,TCPTestSucceeded
Exit-PSSession
Also, I know I can do for-each loops for some of the sections, but I want to get this working as-is first, and then figure out the for-each loops. (I'm VERY much a novice scripter.)