liveBook · Manning

Set-ExecutionPolicy

As explained in Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

Set-ExecutionPolicy is a PowerShell command that changes the execution policy.

Set-ExecutionPolicy changes PowerShell's execution policy, which controls whether scripts can run. On Windows 10, the default Restricted setting allows interactive commands but blocks scripts. section 4.1.1

Check before changing

Run Get-ExecutionPolicy to view the current setting. Run Set-ExecutionPolicy to change the local policy; changing the machine-wide registry setting usually requires administrator privileges. section 4.1.1

Account for the available policy mechanisms:

  • Set-ExecutionPolicy changes the setting in the local machine portion of the Windows Registry. section 4.1.1
  • A Group Policy Object overrides the local setting, so Set-ExecutionPolicy may report that its change had no effect. section 4.1.1
  • PowerShell.exe -ExecutionPolicy can override both local and Group Policy settings for that invocation. section 4.1.1
File C:\Scripts\Get-DiskInventory.ps1 cannot be loaded because the execution 
 of scripts is disabled on this system. Please see "get-help about_signing"
 for more details.

Use the representative error to recognize when a disabled execution policy prevents a script from loading. section 4.1.1

How Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS covers it

How deep it goes
Explains inspection, local changes, administrative permissions, and policy overrides without detailing every policy value.
Examples
Uses Get-ExecutionPolicy, Set-ExecutionPolicy, a disabled-script error, Group Policy settings, and the PowerShell.exe switch.
What it assumes
Assumes basic PowerShell command use and explains administrator permissions for machine-wide policy changes.
What you can do after
Operate/configure execution policy and diagnose why a local change does not permit script execution.
How it connects
Connects execution policy with PowerShell scripts, Group Policy, Windows Registry, and PowerShell.exe.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS. The section links point to the parts of the book it draws on.