Scenario 6 – running a ping test
Before doing any automation on the list of computers, the most important aspect to be tested is whether the computer is reachable or not. If the computer is offline, there is no point in running any automation script block on the computer. Executing script blocks on offline computers will just increase the script execution time. So, it is always advised that you perform a ping test on the list of computers we get as input and run the block of automation script only on the computers that are reachable.
Sometimes, server administrators disable ping on the server. This code works only if the ping is not disabled at the firewall level.
Prescripting activities
The following code assumes that we have a complist.txt
file in the D
drive, which contains the list of all the computer names that are to be tested whether they are reachable or not:
$CompList = Get-Content -Path "D:\PowerShell\Complist.txt"
foreach ($Comp in $CompList)
{
If (test-Connection -ComputerName...