Created
March 5, 2018 17:45
-
-
Save jmelosegui/62a6122f9bfc8112f1465890be1c5835 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
Param ( | |
[Parameter(Mandatory)] | |
[ValidateScript({Test-Path $_ -PathType Leaf})] | |
[string]$ConfigurationDataFile | |
) | |
Set-StrictMode -Version Latest | |
$ErrorActionPreference = "SilentlyContinue" | |
function Get-ConfigurationDataAsObject | |
{ | |
[CmdletBinding()] | |
Param ( | |
[Parameter(Mandatory)] | |
[Microsoft.PowerShell.DesiredStateConfiguration.ArgumentToConfigurationDataTransformation()] | |
[hashtable] $ConfigurationData | |
) | |
return $ConfigurationData | |
} | |
function Test-NetworkConnection | |
{ | |
[CmdletBinding()] | |
Param ( | |
[Parameter(Mandatory)] | |
[string] $ServerName, | |
[Parameter(Mandatory)] | |
[int] $Port | |
) | |
$Socket = New-Object System.Net.Sockets.TcpClient($ServerName, $Port) | |
If ($Socket) | |
{ $Stream = $Socket.GetStream() | |
$Writer = New-Object System.IO.StreamWriter($Stream) | |
$Buffer = New-Object System.Byte[] 1024 | |
$Encoding = New-Object System.Text.AsciiEncoding | |
#Save all the results | |
While($Stream.Available) | |
{ | |
$Read = $Stream.Read($Buffer, 0, 1024) | |
$Result += ($Encoding.GetString($Buffer, 0, $Read)) | |
} | |
Write-output "Connection made successfully $($ServerName):$Port" | |
} | |
else | |
{ | |
Write-Warning "Unable to connect to host: $($ServerName):$Port" | |
} | |
Write-output " " | |
} | |
Clear-Host | |
$ConfigurationData = Get-ConfigurationDataAsObject $ConfigurationDataFile | |
$ConfigurationData.AllNodes | ForEach-Object { | |
$server = $_.NodeName | |
write-output " " | |
write-output "*********************************************" | |
write-output "Testing connection from Localhost to..." | |
write-output $server | |
write-output "*********************************************" | |
$_.Ports | ForEach-Object { | |
Test-NetworkConnection -ServerName $server -Port $_ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use a file similar to the following to test network connectivity.