The summary.
SET EXIT-ON-ERROR AND QUOTE EVERY VARIABLE
Without those, a script continues after a failure and causes damage, and an unquoted variable splits on spaces.
The classic disaster is a deletion where the variable was empty, so the path became the root. Check variables are non-empty before using them in paths.
USE A SHELL SCRIPT LINTER
It catches the majority of common faults automatically.
POWERSHELL PASSES OBJECTS, NOT TEXT
Which removes output parsing entirely — the place traditional shell scripts are most fragile.
YOU HAVE OUTGROWN SHELL WHEN FUNCTIONS AND ARRAYS APPEAR
Move to a general-purpose language then, for error handling, testability and libraries.
SCHEDULED TASKS RUN WITH A MINIMAL ENVIRONMENT
Use absolute paths, always. Scripts working manually and failing when scheduled is nearly always this.
ALERT WHEN A SCHEDULED TASK DOES NOT RUN, NOT ONLY WHEN IT FAILS
A task silently ceasing is invisible for months.