Stuck with PowerShell to enable script execution? We can help you.
Usually, users can’t run any scripts by just double-clicking a file. It is a troublesome process.
As a part of our Server Management Services, we assist our customers with script policy queries.
Today, let’s discuss how our Support Engineers do it easily for our customers.
A quick look at PowerShell
Windows PowerShell is an object-oriented automation engine and scripting language built on .NET.
In addition, it helps system administrators and power-users to rapidly automate tasks.
.ps1 file is the extension for the PowerShell script. By default, we can’t run a script by just double-clicking a file.
This usually restricts the accidental harm from happening.
During the execution of scripts via PowerShell, it seems like there are some policies that restrict the script execution from happening.
Execution Policies during PowerShell script execution
Let us now discuss some major policies. We get one of these outputs during script execution.
Restricted: This message will pop up when we first run any script. This is because Scripts are not allowable here
AllSigned: Here, with this setting, the script will ask for confirmation that we need to run before its execution.
Unrestricted: Here, there are no restrictions present. We can run any scripts that we want.
RemoteSigned: In this case, we can run the scripts that are only signed by a trusted developer.
How we enabled Script Execution in Powershell?
Recently, one of our customers approached us with the following error message.
File C:\Common\Scripts\hello.ps1 cannot load because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.
Our Support Engineers checked the error and in order to fix it, we went ahead with the below steps:
Initially, we open the PowerShell command prompt with the ‘Administrator’ privilege.
Then we enter the following commands.
- Firstly we execute Get-ExecutionPolicy with result as “Restricted”.
- Then, to make it unrestricted we execute the “set-execution policy unrestricted” command.
- Next, it asked for confirmation“Do you want to change the execution policy”. By default, it is set to “N” and we need to change it to “Y”.
- Finally, we execute the Get-ExecutionPolicy command so as to check the changed policies. It results in unrestricted privilege.
After doing all these we create a file in notepad and save it with an extension.ps1. For example, myscript.ps1
In the PowerShell, we call the script using the command & “X:\myscript.ps1”
Thus, we enabled the script execution in PowerShell.
[Couldn’t fix the error?- We’re available 24/7.]
In short, we changed PowerShell to enable script execution by running some commands. Today, we discussed how our Support Engineers resolve the script error for our customers.