I am attempting to write a script that takes a list of IP address’s, finds alive hosts, then checks to make sure that a specific service is installed. If the service is NOT installed it should be adding the IP address to the $notinstalled array. This is not working as I thought it should.
Could someone tell me what I am doing wrong in that specific ForEach section? This script is a learning / work in progress as I have never written a powershell script before.
Well, you’ve suppressed the error by using -EA SilentlyContinue. You have to use -EA Stop to trigger Try/Catch. See our free ebook on error handling - under the “Resources” menu on the site.
Your try/catch block should probably be inside the foreach loop, not the other way around (unless you want the whole loop to abort as soon as an error occurs.)