Share this post:This blog post is part of an ongoing series by Adam Gordon. Adam will show you how to use each PowerShell command each week. Adam will be covering Set-ExecutionPolicy this week.

When to use Set-ExecutionPolicy
You can set PowerShell execution policies on Windows computers.
PowerShell security strategy includes an execution policy. Execution policies control whether you are allowed to load configuration files such as your PowerShell profile or run scripts. Before scripts can be run, they must be digitally signed.
The default scope of the Set-ExecutionPolicy cmdlet is LocalMachine. This affects everyone who uses the computer. Start PowerShell and Run as Administrator to change the LocalMachine execution policy.

How to use Set-ExecutionPolicy
Establish a policy for execution
Set-ExecutionPolicy
Get-ExecutionPolicy -List
The ExecutionPolicy parameter is used by the Set-ExecutionPolicy cmdlet to specify the RemoteSigned Policy. Scope is the parameter that specifies the scope value, LocalMachine. You can view the execution policy settings by using the Get-ExecutionPolicy cmdlet and the List parameter.

Apply the execution policy to a remote computer to a computer at home:
Invoke-Command -ComputerName Server01 -ScriptBlock Get-ExecutionPolicy | Set-ExecutionPolicy
The Invoke–Command cmdlet executes at the local computer, and sends the scriptblock to the remote computer.
The ComputerName parameter indicates the remote computer, Server01.
The ScriptBlock parameter runs Get–ExecutionPolicy from the remote computer.
The Get-ExecutionPolicy object goes down the pipeline to Set-ExecutionPolicy.
Set-ExecutionPolicy applies execution policy to the local computer’s default scope, LocalMachine.

Eliminate the execution policy for the current administrator:
Set-ExecutionPolicy
Get-ExecutionPolicy -List
The ExecutionPolicy parameter is used by the Set-ExecutionPolicy cmdlet to specify the Undefined Policy. Scope is the parameter that specifies the scope value, CurrentUser. You can view the execution policy settings by using the Get-ExecutionPolicy cmdlet and the List parameter.

Set the execution policy of the current PowerShell session
Set-ExecutionPolicy
Get-ExecutionPolicy -List
The current PowerShell session is not affected by the Process scope. The execution policy is saved in the environment variable $env:PSExecutionPolicyPreference and is deleted when the session is closed.
The ExecutionPolicy parameter is used by the Set-ExecutionPolicy cmdlet to specify the AllSigned Policy. Scope is the parameter that specifies the value, Process. You can view the execution policy settings by using the Get-ExecutionPolicy cmdlet and the List parameter.

Do you need PowerShell training? ITProTV offers PowerShell online IT training courses.