Securing PowerShell against inadvertent mistakes
The first set of tools we’ll look at are the ones that protect us from people doing things by accident. The most useful of these is a built-in execution policy that can be used to control how scripts can be run.
Execution policy
We encountered the execution policy feature back in Chapter 8, Writing Our First Script – Turning Simple Cmdlets into Reusable Code, and noted that we would cover it in more detail in this chapter. The execution policy is a safety feature that controls how we can run scripts, but only in a Windows environment. Don Jones (the Don!) has described the execution policy as intended to “…slow down an uninformed user who is unintentionally trying to run an untrusted script.” There is a lot of unintentionality in that sentence. The execution policy will present a few obstacles to an educated user who is deliberately trying to run a script. The best way to stop a user from running...