Skip to content

Instantly share code, notes, and snippets.

@bryanvine
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanvine/f6f339d8ca0a5fe269e5 to your computer and use it in GitHub Desktop.
Save bryanvine/f6f339d8ca0a5fe269e5 to your computer and use it in GitHub Desktop.
Quick Script - Check if servers are pingable and have RDP port TCP 3389 open
Param(
[String] $Servers
)
$srvrs = gc $servers
$collection = @()
foreach ($srv in $srvrs){
$serverStatus = New-Object PSObject
$serverStatus |Add-Member NoteProperty ServerName $srv
$serverStatus |Add-Member NoteProperty TimeStamp (Get-Date -f s)
$serverStatus |Add-Member NoteProperty RDPPort 3389
Try{
if((New-Object System.Net.Sockets.TCPClient -ArgumentList $srv,3389 -ErrorAction SilentlyContinue ) -and (Test-Connection $srv -Count 2 -ErrorAction SilentlyContinue -Quiet)){
$results = "Up"
}
else{$results = "Down"}
} catch {
$results = "Down"
}
$serverStatus |Add-Member NoteProperty Results $results
$collection += $serverStatus
}
$collection | Export-Csv .\ServerStatus.csv -NoTypeInformation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment