The accepted answer is right, but the policy modification is only available for the currently running instance of the Powershell, meaning once the instance of the Powershell is shut down. The policy will be reset. If a user reopens another instance of Powershell, the default policy will be applied which is Restricted
For me, I need to use the VisualStudio Code console and g++ from cygwin to build things. The console is using Powershell, with the default policy, nothing can be done. One solution is changing the policy everytime the console is fired in VisualStudio Code console, maybe a script of changing the policy.
I am lazy, so another solution is when I run the Powershell in admin mode, similar to what the accepted answer does. but with an extra parameter which changes values in the Registry table. Once it been done. Other instances of Powershell will use the RemoteSigned policy by default.
set-executionpolicy remotesigned -Scope CurrentUser
3Will this change the policy permanently or do I have to do this every time I restart my computer? – Ray – 2017-01-14T18:11:37.930
3@Ray This will change the policy permanently. – Pavel Chuchuva – 2017-01-14T22:15:09.507
1
@Ray See the documentation. By default, it sets it for the
– jpmc26 – 2018-07-17T18:38:32.443LocalMachine. To set for other scopes (CurrentUserorProcess), pass-Scopeexplicitly.@PavelChuchuva should I add this line on top of my script you meant – FabioSpaghetti – 2019-07-16T10:14:26.447
@FabioSpaghetti No need to add anything to your scripts. Just execute that command once by following the steps. – Pavel Chuchuva – 2019-07-17T03:21:48.380
@Pavel where? In cmd prompt? – FabioSpaghetti – 2019-07-17T04:37:20.983
@FabioSpaghetti Yes or in a PowerShell console – TylerH – 2019-09-24T19:42:50.530
1I would mention you need to do that two times, in normal power shell, and once more in
Windows PowerShell (x86)It’s very unexpected but the 2 have different set of policies. – Soonts – 2019-10-29T23:30:08.617