Last active
July 25, 2024 08:13
-
-
Save bryanvine/e3ca74974d8b6c46b201 to your computer and use it in GitHub Desktop.
Quick Script Function Test-PingRDP - make a report from a list of servers, testing if it responds to a ping and has RDP open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function Test-PingRDP { | |
| Param( | |
| [String]$ServerList, | |
| [String]$CSVOutput = ".\ServerStatus.csv" | |
| ) | |
| $collection = @() | |
| Get-Content $serverList | ForEach-Object{ | |
| $serverStatus = New-Object PSObject | |
| $serverStatus |Add-Member NoteProperty ServerName $_ | |
| $serverStatus |Add-Member NoteProperty TimeStamp (Get-Date -f s) | |
| $serverStatus |Add-Member NoteProperty RDPPort 3389 | |
| Try{ | |
| if((New-Object System.Net.Sockets.TCPClient -ArgumentList $_,3389) ` | |
| -and (Test-Connection $_ -Count 2 -Quiet)){ | |
| $results = "Up" | |
| } | |
| else{$results = "Down"} | |
| } catch { | |
| $results = "Down" | |
| } | |
| $serverStatus |Add-Member NoteProperty Results $results | |
| $collection += $serverStatus | |
| } | |
| $collection | Export-Csv $CSVOutput -NoTypeInformation | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment