Table of Contents
Fix 1 - Tweak PowerShell
Fix 2 – Change Execution Policy
Home Common Problem How to disable script execution in PowerShell on Windows 10/11?

How to disable script execution in PowerShell on Windows 10/11?

Apr 21, 2023 pm 11:55 PM
powershell Registry Editor

PowerShell is an excellent and advanced cross-platform task automation solution. Creating and running PowerShell scripts on Windows systems is generally very easy. However, you may be blocked by "Running scripts is disabled on this system". " If you run a script on your system, you will see an error message. If your system administrator has set a policy that prevents any unauthorized scripts from running on your system, you will see the specified error message. You must cancel Block policy or tweak the registry and you can run any script.

Fix 1 - Tweak PowerShell

You can run code bypassing the current execution policy. So you don't have to tamper with it, but you You can run your script.

1. After pressing the Windows key and S key at the same time, enter "powershell".

2. Then, Right-click on "Windows PowerShell" and click "Run as administrator".

修复:在 Windows 11 ,10 上的 PowerShell 中在此系统上禁用运行脚本

3. When the Windows PowerShell screen appears , type this code and change it accordingly, then press Enter to execute it.

1

powershell -ExecutionPolicy ByPass -脚本文件名.ps1

Copy after login

[

Just replace " nameofthescript .ps1” with the name of the script you are trying to run.

Example – Assuming the name of the script is “myscript”, the command would be –

1

powershell -ExecutionPolicy ByPass -File myscript.ps1

Copy after login

]

修复:在 Windows 11 ,10 上的 PowerShell 中在此系统上禁用运行脚本

This way you can run any script without changing the current script execution policy. However, this won't work if you want to batch execute scripts or create automated scripts Effect.

You must look for the next fix for this.

Fix 2 – Change Execution Policy

You can change the current execution policy settings if you wish.

1. Press the Windows key again and enter " powershell".

2. Later, right-click " Windows PowerShell" and click "Run as administrator" to open a terminal with administrative rights.

修复:在 Windows 11 ,10 上的 PowerShell 中在此系统上禁用运行脚本

##3. When it opens,

Type this command to change the execution policy according to your choice.

1

Set-ExecutionPolicy RemoteSigned

Copy after login
Copy after login

[

You can set the script execution policy to four different modes. These are -

Restricted – The default mode where PowerShell does not allow any scripts to be run on the system.

AllSigned – Only signed and authorized scripts are allowed in this mode Run.

RemoteSigned - In this mode, all scripts you download must be signed by a trusted signature.

Unrestricted - You can run any script you like. There are no boundaries to trusted signatures or trusted publishers.

Example – Suppose you want to set the policy setting to “RemoteSigned”, the command would be –

1

Set-ExecutionPolicy RemoteSigned

Copy after login
Copy after login

]

After that, press “

Y” and press Enter.

修复:在 Windows 11 ,10 上的 PowerShell 中在此系统上禁用运行脚本

4. If you encounter any error message, just run this command.

1

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

Copy after login

Again, write "

Y " and press Enter.

修复:在 Windows 11 ,10 上的 PowerShell 中在此系统上禁用运行脚本

Once you have done this, you can easily run the script as needed.

Test by running the script.

Note——

Script execution policies are often restricted because misconfigured or faulty scripts can cause fatal damage to the system. So once you've finished running the script, you can set the execution policy to "restricted" mode again.

1. Access PowerShell with administrative rights.

2. Now, just execute this single code to restrict any policy from running on the system.

1

设置 ExecutionPolicy 受限

Copy after login

3. Enter "

Y" again and press Enter key.

修复:在 Windows 11 ,10 上的 PowerShell 中在此系统上禁用运行脚本

After that, close the PowerShell window.

Fix 3 – Edit the Registry

If you encounter any error messages while changing the execution policy, you can edit the Registry Editor.

1. Just enter "

regedit.msc" in the search box of the taskbar.

2. After that, click on “

Registry Editor” to access it.

修复:在 Windows 11 ,10 上的 PowerShell 中在此系统上禁用运行脚本

警告 – 您将调整您的注册表。由于注册表编辑器是您系统中非常重要的一部分,您应该事先做好注册表备份。

当注册表编辑器打开时,点击“文件”。然后点击“导出”在您的系统上创建一个新的注册表备份。

修复:在 Windows 11 ,10 上的 PowerShell 中在此系统上禁用运行脚本

稍后,如果出现问题,您可以使用此备份。

3. 现在,以这种方式展开左侧——

1

计算机\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\ShellIds\ScriptedDiagnostics

Copy after login

4. 然后,双击“ ExecutionPolicy ”二进制值。

修复:在 Windows 11 ,10 上的 PowerShell 中在此系统上禁用运行脚本

5. 只需在“数值数据:”框中写下“不受限制”。

6. 然后,点击“确定”保存此更改。

修复:在 Windows 11 ,10 上的 PowerShell 中在此系统上禁用运行脚本

之后,关闭注册表编辑器。关闭注册表编辑器后,重新启动系统。

重新启动计算机后,您可以轻松运行您选择的脚本。

The above is the detailed content of How to disable script execution in PowerShell on Windows 10/11?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Unable to delete ISO file opened in system: How to fix it Unable to delete ISO file opened in system: How to fix it Apr 16, 2023 pm 02:25 PM

What is an ISO file? An ISO file is a file that contains an exact copy of an optical disc, such as a DVD or CD. This type of disc image can be installed on your computer and appear as if you have an optical drive connected to your computer and a CD or DVD containing data inserted into the drive. ISO files can also be used to burn new copies of the DVDs or CDs from which they were created, or simply to contain a large number of files in a single file that is easy to download. ISO files are often quite large; when you're done with them, you'll most likely want to

How to disable display scaling for high DPI settings in Windows 11 or 10 How to disable display scaling for high DPI settings in Windows 11 or 10 May 22, 2023 pm 10:11 PM

The default display scaling feature on Windows 10 or later is a core component of the Windows operating system. But sometimes, this feature of certain apps can cause compatibility issues, unreadable text, blurry logos, and ultimately, app crashes. This can be a huge headache if you're dealing with 2160p or higher resolutions. There are many ways to disable the default display scaling feature on high DPI settings. We've selected the best ones and detailed step-by-step instructions for each process. How to Disable Display Scaling on High DPI Settings There is a way, all you have to do is disable high DPI scaling for a single application, and there is a way to do it for the entire Window

How to use Nishang, the PowerShell penetration testing tool How to use Nishang, the PowerShell penetration testing tool May 13, 2023 am 10:58 AM

Initial PowerShell, first let's understand the concept: PowerShell can be regarded as an upgraded version of cmd (bat scripting language), which is a scripting language on the Windows platform. It is object-oriented and closely related to .NetFrameWork. It can also be thought of as the bashshell on Windows. Windows PowerShell is a command line shell and scripting environment that enables command line users and script writers to take advantage of the power of the .NET Framework. It introduces a number of very useful new concepts, further extending what you get in the Windows Command Prompt and WindowsHost environments

Fix: PowerShell cannot be opened or PowerShell has stopped working in Windows 11/10 Fix: PowerShell cannot be opened or PowerShell has stopped working in Windows 11/10 Apr 24, 2023 pm 07:49 PM

Many users have reported issues with Windows PowerShell stopping working or not opening at all. One of the most common reasons for seeing the PowerShell has stopped working message is that there is a hidden virus on your computer. This in turn will slow down your system and other processes on the system will stop functioning. The error message does not provide any information about the cause of this problem, making it difficult to resolve. If you are annoyed with PowerShell not running or opening issues on your PC, then this article is for you. In this article, we have discussed some of the solutions you can use to fix this error. Fix 1 – Disable and re-enable Windows PowerShell 1. Use Ctr

How to open PowerShell as administrator on Windows 11 How to open PowerShell as administrator on Windows 11 May 10, 2023 pm 06:40 PM

How to Open PowerShell as Administrator on Windows 11 Running PowerShell with elevated or administrator-level permissions allows you to run commands that bypass Windows file protection, such as those used for Windows installation files. You can run PowerShell by opening PowerShell directly or by opening the new Windows Terminal application, which uses PowerShell to run commands by default. Open PowerShell as administrator on Windows 11: Open the start menu and type powershell or terminal. from the right

Select where to get apps missing issue in Windows 11/10 Select where to get apps missing issue in Windows 11/10 Apr 14, 2023 am 11:22 AM

Windows provides users with an option so that they can choose to get their apps from "Anywhere" to "Microsoft Store Only." However, in some cases, Windows users have reported an issue where they cannot find the "Choose where to get apps" option that is missing from the Settings page. This can be a nightmare situation for you, like setting it to app store only mode, you can't sideload any apps from anywhere! Don't worry. You can apply a registry fix to resolve this issue. Workaround –1. Restart the system. If this is a one-time failure, restarting should fix it. 2. You need an administrator account to

How to enable an administrator account on Windows 11 How to enable an administrator account on Windows 11 Apr 15, 2023 pm 07:46 PM

How to Enable or Disable an Administrator Account on Windows 11 Using PowerShell One of the quickest ways to enable an administrator account on Windows 11 is to use PowerShell. You can also use the newer Windows Terminal or, if you prefer, the older Command Prompt (cmd) tool. You need to make sure you run these commands from a user account that already has administrator rights. If you are using a standard user account, you will need to switch to another user account to run this tool. To enable an administrator account using PowerShell on Windows 11: Open by clicking the Start button or pressing the Windows key

PowerShell deployment fails with HRESULT 0x80073D02 issue fixed PowerShell deployment fails with HRESULT 0x80073D02 issue fixed May 10, 2023 am 11:02 AM

Do you see this error message "Add-AppxPackage: Deployment failed with HRESULT: 0x80073D02, The package cannot be installed because the resource it modifies is currently in use. Error 0x80073D02..." in PowerShell when you run the script? As the error message states, this does occur when the user attempts to re-register one or all WindowsShellExperienceHost applications while the previous process is running. We've got some simple solutions to fix this problem quickly. Fix 1 – Terminate the experience host process You must terminate before executing the powershell command