HOWTO enable Powershell script execution

updated: 09/10/2021

 

Powershell is indeed a very powerful tool, and sometimes we may need to commit several similar operations that we can quickly organize in a script.  By default, you cannot execute any unsigned PowerShell script.  This can be a problem if we don’t know how, or you need to do a quick maintenance task.

We can update this setting, by opening a Powershell window with administrative access rights and use set-executionpolicy command.

Using it without the ‘-scope‘ parameter will update the local ‘global’ policy.  This might be a possible security problem.

A good idea might be to start to see how is currently set the execution policy, by typing the following command:

get-executionpolicy -list

Usually, they are all set to ‘undefined’ with the only exception of ‘localmachine’ set to ‘remotesigned’.

The solution

Finally, we can enable the script execution without opening a security problem by typing this command:

set-executionpolicy unrestricted -scope currentuser

We can undo it by the following command:

set-executionpolicy undefined -scope currentuser