PowerShell execution policies

Change and view the current PowerShell execution policies.

Current options

  1. Unrestricted
    Allow all scripts
  2. RemoteSigned
    Allow local scripts and remote signed scripts
  3. AllSigned
    Allow only signed scripts
  4. Restricted
    Permits individual commands, but does not allow scripts.

How it works

Its requesting the Powershell ExecutionPolicy for LocalMachine then it sets this in a variable to later be recalled in the echo command.
There we are requesting the %executionpolicyLM% and printing it in the colour cyan.

Say ExecutionPolicy
  FOR /F "tokens=* USEBACKQ" %%F IN (`Powershell Get-ExecutionPolicy LocalMachine`) DO (
  SET executionpolicyLM=%%F
  )

  echo %ESC%[97mCurrent ExecutionPolicy Local Machine: %ESC%[96m%executionpolicyLM%

Opens powershell with no profile bypassing the executing policy.
Then it will open a new powershell with admin and use the following command Set-ExecutionPolicy Restricted -Force -Scope LocalMachine
This sets the ExecutionPolicy to Restricted for the LocalMachine

Set ExecutionPolicy
  PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList 'Set-ExecutionPolicy Restricted -Force -Scope LocalMachine' -Verb RunAs}"