DEV Community

ogunsolu007
ogunsolu007

Posted on

Overcoming Execution Policy Restrictions in PowerShell: My Journey with the HNG Internship

I decided to embark on django backend development through HNG intership. setting up my virtual environment was the first starting point where i encoutered issues with power shell. and i will like to share how i was able to find solution to the issue. below is the error message encoutered.

PS C:\Users\qwerty\documents\learn-django> .\myvirenv\Scripts\Activate

.\myvirenv\Scripts\Activate : File C:\Users\qwerty\documents\learn-django\myvirenv\Scripts\Activate.ps1 cannot be
loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1

  • .\myvirenv\Scripts\Activate
    + ~~~~~~~~~~~

    • CategoryInfo : SecurityError: (:) [], PSSecurityException
    • FullyQualifiedErrorId : UnauthorizedAccess PS C:\Users\qwerty\documents\learn-django>
  • first i try to understand the problem.The error message indicated that running scripts is disabled on my system due to PowerShell's execution policy settings. PowerShell's execution policy is a safety feature that controls the conditions under which PowerShell loads configuration files and runs scripts. By default, it is set to restrict the execution of scripts to prevent the running of potentially harmful scripts.

  • Opened powershell as an administrator to confirm the current status of the execution policy with the following command

Get-ExecutionPolicy

  • It returned RESTRICTED, this confirms that no script was allowed to run

  • To allow the activation script to run, I needed to change the execution policy. There are several options available, but I opted for the RemoteSigned policy, which allows scripts created on the local computer to run but requires that scripts downloaded from the internet be signed by a trusted publisher. below is the command for this

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

after these step i ran my virtual environment setup again , and it was successful.

Technical challenges are an inevitable part of a developer’s journey, Here’s to a successful journey with the HNG Internship, where I look forward to tackling more challenges, learning new skills, and growing as a backend developer!. HNG provides a platform for growth and excellence. follow this links for more Internship hire

Top comments (0)