I have a script that is performing a tak in a loop. I am generating an email and would like to somehow set a flag across the whole script that can identify if one instance of the task has failed.
Would this be as simple as setting a flag or is there a proper way in Powershell\.net to do this? Code as follows
#Check if there are any error counts, if there are something has gone wrong restoring the DB
if ($errs -ne 0) {
"Something failed when restoring the database...Check the following error(s)..." | out-file -append $GenericLogFile
$i = 0
For(;$i -le $errs; ) {
#Scrape the errors out and post to the log file
$error[$i] | format-list -force | out-file -append $GenericLogFile
$i++
#------This is the flag------#
$broken = $true
}
} else {
" Restored Succesfully" | out-file -append $GenericLogFile
}
Then I'd check wheather $broken was true\false and act accordingly...
Alter De Ruine