Search code examples
powershellcmdippingmsg

Windows pop up message when responds to ping [cmd, PowerShell]


Is it possible to run a specific script and receive a message (like msg command) when the pinged machine becomes available?

ping -n <Address> | find "TTL=" && (
msg * Online
)

Solution

  • Here is a PowerShell way:

    ping -t <Address> | Select-String 'TTL=' | Select-Object -First 1
    msg * Online
    
    • ping -t <Address> repeatedly pings the given host.
    • Select-String 'TTL=' searches each output line of ping for the given RegEx pattern. If found, it is piped to the next command.
    • Select-Object -First 1 ends the pipeline as soon as the first line has been found.
    • This outputs the line containing "TTL=" to the console. If you don't want this, append | Out-Null.