Scripts That Run Without You

A script run by a scheduled task has nobody to answer its questions and doesn't start in its own folder, so it takes parameters instead of asking, builds its paths from $PSScriptRoot, leaves a dated log and a Start-Transcript recording, ends with an honest exit code, and runs as the account the task names.

Updated

Cheat sheet for the lesson Scripts That Run Without You: A script run by a scheduled task has nobody to answer its questions and doesn't start in its own folder, so it takes parameters instead of asking, builds its paths from $PSScriptRoot, leaves a dated log and a Start-Transcript recording, ends…
Category
PowerShell
Level
Freelancer
Tags
exit-code, log-file, operating-system, powershell, principle-of-least-privilege, psscriptroot, start-transcript, system-account