try-catch-fail with powershell and schtasks
I'm new to powershell, but I'm trying to output some simple logging in a ps I'm writing to create scheduled tasks. My code is below. It seems that it doesn't throw an exception when you get an error with schtasks. Another SO question mentioned this with fileIO actions and suggested doing "-ea stop" but that doesn't work with schtasks. #create log file $log = "\\servername\!incoming\Deploy\log.txt" Clear-Content $log #get input file list $txtServerList = Gc "\\servername\!incoming\Deploy\serverlist.txt" #loop through each server ForEach($strServername In $txtServerList) { try { #install task