Anything done by hand will be forgotten

Create a user, set a folder ACL, check a service. The third time is a script. PowerShell’s job is not “writing code”. It is running the same steps, in the same order, with a record.

A safe skeleton first

  • `$ErrorActionPreference = 'Stop'` — don’t swallow failures.
  • `try/catch` should write what broke to a file.
  • `Start-Transcript` (or your own logger) records who ran what, and when.
  • Passwords do not live in the script. Use Credential Manager or a locked-down vault.

Think in commands, not in 400-line files

`New-CorpUser`, `Set-CorpMailbox`, `Export-StaleComputers`. Make parameters mandatory. Document defaults. Helpdesk should not have to ask which script.

Scheduled tasks

A task cannot lean on your interactive profile. Use a least-privilege service account, logon-as-batch, and drop output in a folder. “It worked on my machine” is not a runbook.

Remoting

Don’t expect magic if WinRM is off. Decide who may enter which host, then the HTTPS/WinRM certificate, then the script. Invoke-Command is a signed, permitted, logged channel — not a toy.

Automation is not there to fire people. It is there so the 02:00 check still happens.