In the previous lesson you learned to put every single change behind a question. A runbook is more than one change: it is a procedure that someone starts today, tomorrow and once more after a crash.
For that it needs two properties. It must show beforehand what it does (-WhatIf), and it must do only what is still to be done. The second property is called idempotence, and it turns a script you are afraid of
into one you may repeat.
All examples in this lesson were run with PowerShell 7.6.9 on Windows 11; the native program is git (output from that run, path shortened). The practice folder is called office.
One REST example runs against a small server that the example starts itself on your own machine; it touches no network.
Idempotent: the word and the thing
An operation is idempotent if after the second execution it leaves the same state as after the first. "Create the folder archive" is not (the second call fails or creates something new).
"Make sure the folder archive exists" is. The difference lies in the wording: an idempotent runbook describes a target state, not a sequence of steps.
The pattern has three parts: read (what is there?), compare (what is missing, what is too much, what is wrong?), change (only the difference). The reward: a run after a crash continues where it stopped,
a run with nothing to change does nothing, and the preview is precise because reading and comparing really run even with -WhatIf.