10.03.2025

About Execution Policies Powershell

Operating systems have developed a whole pool of security measures to mitigate and detect malicious activity at various stages. Authentication subsystems, authorisation, privilege escalation controls, anti-virus solutions, group policies and more, allowing for a wider range of system control.

In this article we will look at one of these security mechanisms and learn how to configure policies to control the launch of scripts on the OS!

What are Execution Policies?

Literally we can interpret this mechanism as execution policies for PowerShell scripts. The PS interpreter itself is an OS shell that manages services, processes, devices and control of OS objects in general.

Before running commands, the interpreter can perform additional checks according to its configurations and mechanisms. One of them Execution Policies sets a policy for an object by which it will be determined whether the current script can be run.

For example, a user on our domain network decides to open a script that is potentially malicious according to our policy:

Screenshot № 1 — Error of running script

We get a logical answer that the system has a policy that prohibits the launch of scripts. The policy itself can be set with the command:

Set-ExecutionPolicy -Scope -ExecutionPolicy -Force

Where the values of scope or scope, as well as the category of the prohibition policy itself vary. You can select one of the presented scopes:

Priority of application: if the parameter is set in several places at once, the priority will be as follows:

The logic behind this prioritization is quite clear, for the bulk of the devices the configuration is done through GPOs, selecting users and machines. For those users or devices that are not affected by the policies are used settings from the registry. But where without exceptions in the form of priority for processes.

And the presented variations of policy types perform the following functions:

Once we've covered the basic options and syntax, let's get practical!

How do I configure Execution Policy via GPO?

To get started, you can find out what policy is set on your machine now with the command:

Get-ExecutionPolicy

Screenshot № 2 — Current Policy

After you can set policies globally via GPO, on a domain controller go to:

Computer Configuration → Windows Settings → Administrative Templates → Windows Components → Windows PowerShell

.

You need to enable the policy as well as its type:

Screenshot № 3 — Current Policy

Then save and apply to an organisational unit of devices or users:

Screenshot № 4 — Link Policy to Organizational Unit

On the client device, you can update the policies without waiting for the automatic update Win+X → Terminal/PowerShell:

gpupdate /force

Screenshot № 5 — Update policy

And after that, let's check the settings via the command:

Get-ExecutionPolicy -list

Depending on whether you have assigned the policy to devices or users, the MachinePolicy or UserPolicy parameter will be changed.

How do I configure Execution Policy via PS?

If you want to change the settings locally on your machine, then run the command we have explained earlier. For example, let's allow local scripts but disallow unsigned remote scripts:

Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy RemoteSigned -Force

Screenshot № 6 — Block execution

Note that the actions must be performed by a person who has permissions to the registry branch. After we run an unsigned file from an external network, usually such files have a MotW tag that marks the file as external. The policy worked and the script was not run, this mechanism is great for mitigating malicious activity in a domain network on endpoints, in server solutions. This tool would be a great addition to your existing AppLocker policy and file launch zones!

If you don't have sufficient resources than you can perform actions on powerful cloud servers. Serverspace provides isolated VPS / VDS servers for common and virtualize usage.

Screenshot №7 — Create Server