r/ScriptSwap • • Jun 30 '16

Server Ping Script for r/2007scape

I'm trying to make a script that will ping old school runescape servers and output the results to a text file in the temp folder. I'd really like some help with finding a way to display the results via domain name (or server name) instead of IP. This is my first powershell script, so feel free to shred my script!

https://github.com/FireSpark142/RunescapePing/blob/master/RunescapePingTest.ps1

5 Upvotes

2 comments sorted by

View all comments

Show parent comment

1

u/brian4120 Jun 30 '16

Realized you were already using the hostname of the server, so no Resolve-DNSName is needed.

Slow morning so I rewrote your script to take in a list of Servers then report Online/Offline status.

#Clear Server_Status.txt
Out-File -FilePath "C:\temp\Server_status.txt" -Append -InputObject $null -Force

#Get content from servers.txt file. On each line run test-connection to determine if online
#Then write processed server name + Online/Offline status to Server_status.txt
Get-Content c:\temp\servers.txt | Foreach-Object {
 if (test-connection -ComputerName $_ -Quiet -Count 1) {
    $SvrStatus = "Online"
    } else {
    $SvrStatus = "Offline"
    }

    #Create a Variable to hold our formatted text. Take Current item and add the Offline/online status
    $StatusOutput =  "$_ = $SvrStatus"

    #Write Console Output for currently processed Server
    Write-Output  $StatusOutput

    #Write currnet Server + Status to file
    Write-Output $StatusOutput | Out-File -FilePath "C:\temp\Server_status.txt" -Append
}

Server.txt format is simple, one server per line

oldschool1.runescape.com
oldschool2.runescape.com
oldschool3.runescape.com
oldschool4.runescape.com
oldschool5.runescape.com
oldschool6.runescape.com
oldschool8.runescape.com

Check out /r/powershell if you are interested in doing more powershell scripting!