Created
March 13, 2014 03:37
-
-
Save ctolkien/9521545 to your computer and use it in GitHub Desktop.
Tests if machines respond on port 80
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
$machines = get-content "machinescsv.txt" #assumes machine names are each on a new line | |
$fileToLogTo = "logOfIIS.txt" #this is where we'll log machines that respond | |
set-content $fileToLogTo $null #reset the contents of the file to nothing | |
$machines | ForEach-Object { #for each machine that we have | |
$socket = (new-object Net.Sockets.TcpClient) #reach into .net and make a TcpClient | |
try { | |
$socket.Connect($_, 80) #attempt to connect | |
Add-Content $fileToLogTo ($_ + "`n") #write to log file | |
Write-Host "Open Port on" $_ -BackgroundColor Green #post to console | |
} | |
catch [System.Exception] { | |
Write-Host "Failed:" $_ -BackgroundColor Red # no iis found! | |
} | |
finally { | |
$socket.Dispose() #cleanup, close socket, etc. | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment