Remember to maintain security and privacy. Do not share sensitive information. Procedimento.com.br may make mistakes. Verify important information. Termo de Responsabilidade
When working with PowerShell on Windows, you might encounter an error message stating, "Não pode ser carregado porque a execução de scripts foi desabilitada neste sistema" (translated: "Cannot be loaded because script execution is disabled on this system"). This error occurs because PowerShell has a security feature that restricts the execution of scripts to prevent malicious activities. By default, the execution policy is set to "Restricted," which prevents any scripts from running.
In this article, I will guide you through the steps to change the execution policy to allow script execution in PowerShell.
PowerShell execution policies are a safety feature that controls the conditions under which PowerShell loads configuration files and runs scripts. There are several execution policies you can set:
To change the execution policy, you need to use the Set-ExecutionPolicy
cmdlet. Here’s how you can do it:
Before changing the execution policy, it’s a good practice to check the current policy. You can do this with the following command:
Get-ExecutionPolicy
To change the execution policy to RemoteSigned
, which is a common choice for allowing script execution while maintaining some security, use the following command:
Set-ExecutionPolicy RemoteSigned
You will be prompted to confirm the change. Type Y
and press Enter.
After setting the new execution policy, verify it by running:
Get-ExecutionPolicy
This should return RemoteSigned
.
Now that the execution policy is set to allow script execution, you can run PowerShell scripts. Here’s an example script that outputs "Hello, World!":
Create a new file named HelloWorld.ps1
with the following content:
Write-Output "Hello, World!"
To execute the script, navigate to the directory containing HelloWorld.ps1
and run:
.\HelloWorld.ps1
You should see "Hello, World!" printed in the PowerShell window.