-
-
Save mavericksevmont/b4f8109c9c86a9053eb6032692b0d130 to your computer and use it in GitHub Desktop.
Ping-Machines
This file contains 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
# Name: Ping-Machines | |
# This is a script created for educational purposes, no puppies were harmed while using write-host | |
# The purpose of this script is to be improved with new features, style and best practices | |
# https://www.youtube.com/playlist?list=PL-CiBNPRVIA2KhV94GXuIv2_nQGvyrkJs | |
Write-Host "Script is running" -ForegroundColor Cyan -BackgroundColor Black | |
$Hosts = Get-Content 'C:\temp\MyScript\Hosts.txt' # Source list of devices to ping | |
$Output = 'C:\temp\MyScript\PingResults.txt' # Results output file location | |
function PingMachines { # Function starts | |
foreach ($_ in $Hosts) { # foreach loop starts here | |
if (Test-Connection -ComputerName "$_" -Count 1 -Quiet) { # if conditional for test-connection | |
Write-Host "$_ is reachable" -ForegroundColor Green # Message to Console | |
Write-Output "$_ is reachable" # Message to file | |
} else { # else conditional statement | |
Write-Host "$_ is NOT reachable" -ForegroundColor Red # Message to Console | |
Write-Output "$_ is NOT reachable" # Message to file | |
} | |
} | |
} | |
PingMachines | Out-File "$Output" -Append -Force # Function runs and exports results | |
Write-Host "Done!" -ForegroundColor Cyan -BackgroundColor Black |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment