## Log Creation for Analysis $LogFile = "C:\Windows\Temp\PortTestLog.txt" Try { New-Item -Path $LogFile -ItemType File -Value "Port Test Log Created. $(Get-Date -Format `"yyyyMMdd HHmmss`")." } ## If creating the dedicated log fails, create a new source and write an event to the event log. Catch { New-EventLog -LogName Application -Source "PortTest" Write-EventLog -LogName Application -Source "PortTest" -EventId 7750 -EntryType Error -Message "Failed to create PortTest log at $LogFile. See error: $_" } $Servers = @( "10.100.51.11", "10.100.30.76", "10.241.88.48", "10.241.88.68", "10.100.78.12", "10.100.78.14", "10.128.7.53" ) ForEach ($Server in $Servers) { $PortTest = Test-NetConnection $Server -Port 52311 If ($PortTest.TcpTestSucceeded -eq "True") { Add-Content -Path $LogFile -Value "Connection to $($PortTest.RemoteAddress) over port 52311 and it was True." } Else { Add-Content -Path $LogFile -Value "Connection to $($PortTest.RemoteAddress) over port 52311 was False." } }