How to Enable and Use Script Execution Policy in Windows PowerShell
PowerShell, by default, allows you to run commands (cmdlets) through its console. To execute a script, you can create a notepad file with the script code, save it with the .ps1 file extension and execute it via the PowerShell console. You can also paste the script directly into the console for execution.
However, if this is your first time executing a script via PowerShell, you will get a "running script is disabled" error. By default, script execution on PowerShell is disabled as a security measure to prevent malicious scripts from running on the system. The following article will show you two ways to enable Script Execution Policy in Windows PowerShell.
How to check the current enforcement policy
You can use a PowerShell cmdlet to get your current execution policy. Knowing the current enforcement policy is necessary to know if you need to change the policy.
To get the policy to execute for the current user:
1. Open Windows PowerShell with admin rights.
2. Type the following command into the PowerShell console and press Enter :
get-executionpolicy
3. Since you encountered an error while executing the script, the returned result may show Restricted for your current execution policy.
4. If you need to see the enforcement policy for all supported scopes:
get-executionpolicy -list
You will need to change the execution policy to RemoteSigned to run the script locally without errors. You can change the execution policy from the Settings and PowerShell apps.
How to enable PowerShell execution policy using the Settings app
You can change and set the PowerShell execution policy to RemoteSigned using the Settings app. All you have to do is adjust the PowerShell settings in the developer section to change the execution policy to enable PowerShell script execution.
To change the execution policy using Settings:
1. Press Win + I to open Settings.
2. Open the Privacy & Security tab in the left pane.
3. Next, click For developers .
4. Click to expand the PowerShell section.
5. Turn on the Change the execution policy to allow local PowerShell scripts to run without signing - Require signing for remote scripts switch .
6. Once done, open PowerShell, type get executionpolicy and press Enter. Execution Policy for the current user is set to RemoteSigned.
7. If you need to disable the enforcement policy, turn on the PowerShell switch and set it to Off .
How to allow scripts to run in PowerShell using PowerShell
You can use the PowerShell cmdlet to set the execution policy to RemoteSigned. The command-line interface makes it easy to change enforcement policies on the fly without using the Settings app.
Also, the Settings app can only enable or disable the RemoteSigned enforcement policy. While PowerShell also allows you to set other policies and scopes.
To change the execution policy using PowerShell:
1. Open PowerShell with admin rights.
2. In the PowerShell window, type the following command and press Enter :
Set-ExecutionPolicy RemoteSigned
3. If prompted, press A to confirm action. This will set the RemoteSigned enforcement policy for all users. If you only want to set the execution policy for Current User , use the Scope parameter followed by the username.
4. For example, to set the RemoteSigned execution policy for CurrentUser , use the following command:
Set-ExecutionPolicy RemoteSgined -Scope CurrentUser
5. Replace CurrentUser in the above command with another user (Scope) according to your requirements.
How to delete Script Execution Policy with PowerShell
If you want to disable script execution, set the execution policy to Undefined using the Set_ExecutionPolicy cmdlet. This is the default state and prevents PowerShell from executing any scripts.
To disable script execution using PowerShell:
1. Open PowerShell with admin rights.
2. Next, type the following command and press Enter to disable script execution for all users:
Set-ExecutionPolicy undefined
3. The above command will set the default execution policy (undefined) for all users. If you want to disable script execution for a specific range, use the following command:
Set-ExecutionPolicy undefined -Scope CurrentUser
4. The above command will disable script execution for CurrentUser .
You should read it
- Execution Plans - Execution plan in MS SQL Server
- How to convert PowerShell script file (.ps1) to .exe by IExpress on Windows 10
- How to use Local Group Policy Editor to tweak your computer
- Mount Network Drive on Windows Client using Group Policy
- Managing Windows networks using Script - Part 13: The script returns all values
- Use Google applications more efficiently with Google Apps Script
- Capture execution diagrams with SQL Server 2005 Profiler
- Detects code execution vulnerabilities in WinRAR, noting more than 100 infringement cases
May be interested
- About PowerShellwindows powershell is a command line utility and new scripting language provided by microsoft. why should i study and care about powershell? because it is a new-style utility? of course, every new utility is claimed to be 'different' from the old ones, but powershell has some components that really distinguish it from other utilities.
- What is Windows PowerShell? How to use Windows PowerShelldo you want to learn the features of windows powershell but don't know how? suggestions for you what is windows powershell? the most convenient way to use windows powershell.
- Instructions on how to use PowerShell in Windows Server 2012what is powershell? windows powershell is a command-line shell language interpreter and scripting language specifically designed for system administrators. built on the .net framework, windows powershell helps it professionals control and automate windows operating system administration tasks as well as applications running on windows server environments.
- What to do when Windows can't find PowerShell?powershell is a handy tool that allows you to automate tasks, fix various errors, and manage several windows installations. but what if it suddenly disappears from your computer?
- 10 tips with PowerShell in Windows Server 2008 - Part 2in the previous article, i have shown you some of the basic functions and tricks that can be done with powershell in windows server 2008. and this time, we will continue with part 2, which is also the end. in powershell series in windows server environment ...
- Test SQL Server with Windows PowerShell - Part 7in this section, i will show you how to get that information in top 10 queries based on cpu performance.
- Use PowerShell to download any file on Windows 10windows powershell is a tool built into windows 10. this tool has the ability to set up more features than command prompt, better operating system control .... most likely, powershell will replace command prompt in the future.
- PowerShell command in Windowswindows powershell is an executable command line and a scripting language specifically designed for system administrators.
- Test SQL Server with Windows PowerShell - Part 4in this next section, i will show you the information about network card and hard drive from the server.
- This PowerShell script can bypass Windows 11 system requirements, Microsoft Accounta new utility is being developed that will help remove the strict system requirements of windows 11.