Mid level · Windows track

Errors and Logging

Stop soft failures from lying to you.

If it ran unattended, the log is the truth.

Soft errors hide damage. Set $ErrorActionPreference = 'Stop' in scripts you care about so failures become visible. Log timestamps so last Tuesday’s run is still readable.

try {

  Copy-Item .\a.txt .\backup\a.txt -ErrorAction Stop

  Write-Log "copied a.txt"

} catch {

  Write-Log "FAILED: $($_.Exception.Message)"

  throw

}
General Windows literacy from Phyllux Tech Field House. Not remote support. Do not run scripts you do not understand. Never disable Defender for speed.
Next lesson Previous