Add-Type -AssemblyName system.windows.Forms 
 
$Form = New-Object -TypeName System.Windows.Forms.Form 
$Form.Size = New-Object -TypeName System.Drawing.Size(500, 350) 
$Form.Text = 'Testeur réseau' 
 
# Label IP 
$LabelIp = New-Object System.Windows.Forms.Label 
$LabelIp.Text = 'Adresse IP :' 
$LabelIP.Location = New-Object System.Drawing.Size(30, 20) 
$LabelIP.Size = New-Object -TypeName System.Drawing.Size(90, 20) 
# TextBox IP 
$TextBoxIP = New-Object -TypeName System.Windows.Forms.TextBox 
$TextBoxIP.Location = New-Object System.Drawing.Size(130, 20) 
$TextBoxIP.Size = New-Object System.Drawing.Size(90, 20) 
 
#Label Port 
$LabelPort = New-Object System.Windows.Forms.Label 
$LabelPort.Text = 'Port (1-65535) :' 
$LabelPort.Location = New-Object -TypeName  
System.Drawing.Size(240, 60) 
$LabelPort.Size = New-Object System.Drawing.Size(90, 20) 
 
# TextBox Port 
$TextBoxPort = New-Object -TypeName System.Windows.Forms.TextBox 
$TextBoxPort.Location = New-Object -TypeName System.Drawing.Size(340, 60) 
$TextBoxPort.Size = New-Object System.Drawing.Size(90, 20) 
 
#Label CheckBox 
$LabelPing = New-Object System.Windows.Forms.Label 
$LabelPing.Text = 'Ping seul :' 
$LabelPing.Location = New-Object -TypeName 
System.Drawing.Size(30, 60) 
$LabelPing.Size = New-Object System.Drawing.Size(80, 20) 
 
# CheckBox Ping 
$CheckBoxPing = New-Object System.Windows.Forms.CheckBox 
$CheckBoxPing.Location = New-Object System.Drawing.Size(130, 60) 
$CheckBoxPing.Add_CheckedChanged( { 
        if ($CheckBoxPing.Checked) { 
            $TextBoxPort.ReadOnly = $true 
        } 
        else { 
            $TextBoxPort.ReadOnly = $false 
        }        
    }) 
 
# Label TrackBar 
$LabelNBPing = New-Object System.Windows.Forms.Label 
$LabelNBPing.Text = 'Nombre de Pings :' 
$LabelNBPing.Location = New-Object System.Drawing.Size(30, 90) 
$LabelNBPing.Size = New-Object System.Drawing.Size(100, 20) 
 
# TrackBar 
$TrackBar = New-Object System.Windows.Forms.TrackBar 
$TrackBar.Location = New-Object System.Drawing.Size(130, 90) 
$TrackBar.Size = New-Object System.Drawing.Size(224, 45) 
 
$TrackBar.Maximum = 20 
$TrackBar.Minimum = 1 
$TrackBar.TickFrequency = 4 
$TrackBar.LargeChange = 4 
$TrackBar.SmallChange = 1 
 
# TextBox TrackBar 
$TextBoxTB = New-Object -TypeName System.Windows.Forms.TextBox 
$TextBoxTB.ReadOnly = $true 
$TextBoxTB.Location = New-Object System.Drawing.Size(360, 90) 
$TextBoxTB.Size = New-Object System.Drawing.Size(30, 20) 
$TextBoxTB.Text = 1 
 
$TrackBar.Add_Scroll( { 
        $TextBoxTB.Text = $TrackBar.Value 
    }) 
 
# Bouton Test 
$ButtonTest = New-Object -TypeName System.Windows.Forms.Button 
$ButtonTest.Text = 'Test' 
$ButtonTest.Location = New-Object -TypeName  
System.Drawing.Size(30, 150) 
$ButtonTest.Size = New-Object System.Drawing.Size(150, 30) 
$ButtonTest.Enabled = $false 
 
# ProgressBar 
$ProgressBar = New-Object System.Windows.Forms.ProgressBar 
$ProgressBar.Location = New-Object System.Drawing.Size(200, 150) 
$ProgressBar.Size = New-Object System.Drawing.Size(200, 30) 
$ProgressBar.TabIndex = 3 
$ProgressBar.Set_forecolor('darkblue') 
 
#TextBox Result 
$TextBoxResult = New-Object System.Windows.Forms.TextBox 
$TextBoxResult.ReadOnly = $True 
$TextBoxResult.Location = New-Object System.Drawing.Size(30, 200) 
$TextBoxResult.Size = New-Object System.Drawing.Size(400, 150) 
 
#Ajout des contrôles à la forme 
$Form.Controls.Add($LabelIp) 
 
$Form.Controls.Add($LabelPort) 
$Form.Controls.Add($LabelPing) 
$Form.Controls.Add($LabelNBPing) 
$Form.Controls.Add($TextBoxIp) 
$Form.Controls.Add($TextBoxPort) 
$Form.Controls.Add($CheckBoxPing) 
$Form.Controls.Add($TrackBar) 
$Form.Controls.Add($TextBoxTB) 
$Form.Controls.Add($ButtonTest) 
$Form.Controls.Add($ProgressBar) 
$Form.Controls.Add($TextBoxResult) 
 
# Traitement du script 
$ButtonTest.add_Click( { 
    $TextBoxResult.Text='' 
    $Result = @() 
    if ($CheckBoxPing.Checked) { 
        $Form.Cursor = [System.Windows.Forms.Cursors]::WaitCursor 
        For ($i = 1 ; $i -le $TextBoxTB.Text; $i++) { 
            $ProgressBar.Value = $i / $TextBoxTB.Text * 100 
            $Result += Test-Connection -ComputerName $TextBoxIP.Text -Count 1 -Quiet 
        } 
        $Text = 'Réussi : {0}    |    Echec : {1}' -f ` 
        $Result.Where{$_ -eq $true}.Count,  
        $Result.Where{$_ -eq $false}.Count 
    } 
    elseif (([int]$TextBoxPort.Text -ge 1) -and  
([int]$TextBoxPort.Text -le 65535)) { 
        $Form.Cursor = [System.Windows.Forms.Cursors]::WaitCursor 
        For ($i = 1 ; $i -le $TextBoxTB.Text; $i++) { 
            $ProgressBar.Value = $i / $TextBoxTB.Text * 100 
            $Result += (Test-NetConnection -ComputerName $TextBoxIP.text -Port $TextBoxPort.Text).TcpTestSucceeded 
        } 
        $Text = 'Réussi : {0}    |    Echec : {1}' -f ` 
        $Result.Where{$_ -eq $true}.Count,  
        $Result.Where{$_ -eq $false}.Count 
    } 
    else { 
        $TextBoxResult.ForeColor = [System.Drawing.Color]::Red 
        $Text = "Erreur lors de la vérification du Port. La  
valeur doit être comprise entre 1 et 65535" 
    } 
    $Form.Cursor = [System.Windows.Forms.Cursors]::Default 
    $TextBoxResult.Text = $Text 
}) 
 
$TextBoxIP.add_TextChanged( { 
....$pattern = '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$' 
    if ($TextBoxIP.Text -Match $pattern) { 
        $ButtonTest.Enabled = $true 
        $TextBoxResult.Text = '' 
    } 
    else { 
        $ButtonTest.Enabled = $false 
        $TextBoxResult.ForeColor = [System.Drawing.Color]::Red 
        $TextBoxResult.Text = "Erreur lors de la vérification de 
l'adresse IP. Vérifiez la syntaxe." 
    } 
}) 
 
$form.ShowDialog()
