I have a very basic PowerShell that accepts a list of Windows Server and Services on them and then stops the Services
Get-Service -ComputerName machine1 -Name service1 -ErrorAction Stop | Stop-Service -WarningAction SilentlyContinue Although I had explicitly mentioned -ErrorAction as Stop, in a case if one of the Server is not reachable, the Powershell doesn't come back. How do I change this behaviour at least in a way to stop processing after a certain amount of time as "n" secs which again can be passed thru parameter?
Test-Connectionlike thisif (Test-Connection machine1 -Count 1 -ErrorAction SilentlyContinue) { ... }if (Test-Connection -ComputerName machine1 -Quiet) {all my current code}Thanks a ton for your suggestion of Test-Connection