Powershell doesn't running scripts even after setting execution policy - powershell

I am trying to run virtualenv script to activate it on powershell using:
.\env\Scripts\activate.ps1
but I get this error:
.\env\Scripts\activate.ps1 : File C:\Users\user\Desktop\tranning\env\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
+ .\env\Scripts\activate.ps1
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
I read this article and I tried to solve this by running powershell as administrator and type this command:
Set-ExecutionPolicy RemoteSigned
but unfortunately nothing change

According to this earlier asked question there are a few other things you can try:
PowerShell says "execution of scripts is disabled on this system."
To summarize from the link:
If you are running from a windows server make sure you set the execution policy on all versions of powershell that you have on the system(both x64 x86 versions of powershell)
OR
Run the following to bypass the Execution Policy:
powershell -ExecutionPolicy ByPass -File script.ps1

Related

firebase.ps1 cannot be loaded because running scripts flutterfire_cli error

firebase : File C:\Users\kami\AppData\Roaming\npm\firebase.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
firebase --version
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
This could be due to the current user having an undefined ExecutionPolicy.
Run PowerShell as Administrator, you could try the following:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
copy the above command and paste it on powershell the press Enter.
and then type A and Enter

Why is the PyCharm Terminal showing "activate.ps1 cannot be loaded because running scripts is disabled on this system"? [duplicate]

This question already has answers here:
PowerShell says "execution of scripts is disabled on this system."
(48 answers)
Closed 8 months ago.
When I try to run ionic commands like ionic serve on the VS Code terminal, it gives the following error.
How can I fix this?
ionic : File C:\Users\Lakshan\AppData\Roaming\npm\ionic.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
+ ~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
I found a way to fix this error.
It is as follows:
First, Open PowerShell with Run as Administrator.
Then, run this command in PowerShell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
After that type Y and press Enter.
This is because of Execution Policy. This defines how powershell scripts will run.
In Default windows desktops, it is Restricted, not allowing any scripts (signed or unsigned) only interactive sessions.
So best is you set using RemoteSigned (Default on Windows Server) letting only signed scripts from remote and unsigned in local to run, but Unrestriced is insecure lettting all scripts to run.
To set run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned as administrator.
This code will fix it:
Set-ExecutionPolicy RemoteSigned –Scope Process
To Bypass this you need to change the Execution policy.
Type this into your terminal.
Set-ExecutionPolicy -Scope CurrentUser
then it will prompt you to supply a value at which point you can set Bypass / RemoteSigned or Restricted.
cmdlet Set-ExecutionPolicy at command pipeline position 1
Supply values for the following parameters:
ExecutionPolicy: "RemoteSigned" or "Bypass" or "Restricted".

VScode cannot be loaded because running scripts is disabled on this system

jshint : File C:\Users\Balarka\AppData\Roaming\npm\jshint.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
+ jshint app.js
+ ~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
You can use:
Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope LocalMachine
or:
Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser
You should enter these commands as Administrator.
There's an answer that was referenced here: https://stackoverflow.com/a/59244943/11518388
Alternatively, you could also edit the properties for Visual Studio Code (right-click on the shortcut, click properties) and force it to always run as an administrator.

How to fix "running scripts is disabled on this system"? [duplicate]

This question already has answers here:
PowerShell says "execution of scripts is disabled on this system."
(48 answers)
Closed 8 months ago.
When I try to run ionic commands like ionic serve on the VS Code terminal, it gives the following error.
How can I fix this?
ionic : File C:\Users\Lakshan\AppData\Roaming\npm\ionic.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
+ ~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
I found a way to fix this error.
It is as follows:
First, Open PowerShell with Run as Administrator.
Then, run this command in PowerShell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
After that type Y and press Enter.
This is because of Execution Policy. This defines how powershell scripts will run.
In Default windows desktops, it is Restricted, not allowing any scripts (signed or unsigned) only interactive sessions.
So best is you set using RemoteSigned (Default on Windows Server) letting only signed scripts from remote and unsigned in local to run, but Unrestriced is insecure lettting all scripts to run.
To set run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned as administrator.
This code will fix it:
Set-ExecutionPolicy RemoteSigned –Scope Process
To Bypass this you need to change the Execution policy.
Type this into your terminal.
Set-ExecutionPolicy -Scope CurrentUser
then it will prompt you to supply a value at which point you can set Bypass / RemoteSigned or Restricted.
cmdlet Set-ExecutionPolicy at command pipeline position 1
Supply values for the following parameters:
ExecutionPolicy: "RemoteSigned" or "Bypass" or "Restricted".

Import-Module PoshRSJob with Executionpolicy RemoteSigned

I downloaded the PoshRSJob module. When I try to import the module it always throws the following error (translated from German):
PS C:\WINDOWS\system32> ipmo "C:\Program Files\WindowsPowerShell\Modules\PoshRSJob"
ipmo : The File "C:\Program Files\WindowsPowerShell\Modules\PoshRSJob\Scripts\TabExpansion.ps1" could not be loaded. The File "C:\Program
Files\WindowsPowerShell\Modules\PoshRSJob\Scripts\TabExpansion.ps1" is not signed digitally. You can't execute this script on your system. More information: "about_Execution_Policies" unter
"http://go.microsoft.com/fwlink/?LinkID=135170"..
In Zeile:1 Zeichen:1
+ ipmo "C:\Program Files\WindowsPowerShell\Modules\PoshRSJob"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : Sicherheitsfehler: (:) [Import-Module], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
Our ExecutionPolicy is RemoteSigned
Is there a way to get this module working in a RemoteSigned environment, without Bypassing the Executionpolicy everytime I use the Module in a Script, and without setting the ExecutionPolicy to Unrestricted?
It might be that Windows is treating the files as remote files despite being on your machine locally. Sometimes Windows will know when files have come from the internet (for example if you download through IE or Edge instead of say, Firefox). Behind the scenes, this is storing zone information in an alternate data stream associated with the file, but that can be modified or stripped off.
Right click the PSD1, PS1, PSM1 files inside the module and choose "Properties" and if there's an unblock option, make sure it's unticked.
Alternatively you could run the cmdlet Unblock-File if you have PowerShell 5.1 or greater.