Scripts
Cheat sheet · https://pcornel.dk/topic.php?topic=3047
Answer
A PowerShell script is a .ps1 file executed by a PowerShell host. Its behavior depends on engine/version, invocation method, parameters, current environment, modules, execution policy/signature rules, working directory and external dependencies.
Remember
- Normal script invocation runs in a script scope; dot-sourcing deliberately executes in the caller scope.
- Execution policy can affect script loading on Windows but is not a security boundary.
- Script success depends on engine/module/dependency context, not file content alone.
- PowerShell terminating errors, non-terminating errors and native process exit codes require explicit handling.
- Reproducible scripts should make inputs, prerequisites, target scope and verification explicit.
First checks
$PSVersionTable— PowerShell edition and versionGet-Command <name>— which cmdlet/function/exe runsGet-Help <cmdlet> -Full— syntax and parametersGet-ExecutionPolicy -List— execution policy per scope
Verify in this order
script file → execution policy check → parsed → runs in its scope → exit code
Where it usually breaks
First mismatch in definition/configuration → security context → service/task/process creation → runtime state → output/side effect → event/performance evidence; preserve identity/native error/pre-state before mutation.
PowerShell → Scripts reference map
| Item | Meaning | Evidence boundary |
|---|---|---|
| .ps1 file | Script source | file presence does not prove execution context |
| Parameter block | Declared inputs | validation does not prove external prerequisites |
| Script scope | Normal isolation boundary | dot-sourcing changes caller scope |
| Exit/error | Execution outcome signal | must account for non-terminating/native failures |
| Verification | Target-state check | stronger than script completion alone |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=3047