﻿# encoding: utf-8
# api: clicky
# type: init-gui
# version: 0.1
# title: Ping button
# description: enables the little ping button atop hostname field in toolbar
# category: ui
# state: stable
# hidden: 1
# nomenu: 1
#
# Enables the ping icon (right hand) in the machine/hostname toolbar.
#

$GUI.w.findName("BtnComputerPng").add_Click({
    $GUI.machine.Background = "Yellow"

    $m = $GUI.machine.Text
    if ($t = Test-Connection $m -Count 1 -ErrorAction SilentlyContinue -ErrorVariable err) {
        $col="#5599ff99"
    }
    else {
        $col="#55ff7755"
        $t = New-Object PSObject -Prop @{Address=$m;Statuscode=$err.Exception}
    }

    $t = $t | FL Address,BufferSize,NoFragmentation,PrimaryAddressResolutionStatus,ProtocolAddress,ReplyInconsistency,ReplySize,ResponseTime,StatusCode,Timeout,TimeToLive,TypeofService,PSComputerName,IPV4Address,IPV6Address | Out-String
    Out-Gui -F $col -B "#ee070f1f" ($t.trim())

    $GUI.machine.Background = $col
})

