Reputation: 21
I hade a problem with 'touch' command , so someone tolled me that i should change the policy (in PowerShell) so I can run the script in vs code ,but the problem is that i couldn't change the policy from restricted to remote signed .
Upvotes: 2
Views: 138
Reputation: 440471
As the error message implies, your command requires elevation, i.e. must be run with administrative privileges.
The reason is that Set-ExecutionPolicy
defaults to the LocalMachine
-Scope
value, which - due to making changes at the machine level, i.e. for all users - requires elevation.
Therefore, you have two options:
Either: Run your Set-ExecutionPolicy
call from an elevated session:
Note:
Interactively, you can create an elevated session by right-clicking on the PowerShell icon in the Start Menu or taskbar and selecting Run as Administrator
Programmatically, you can run the following from a (non-elevated) session (still requires interactive confirmation / authorization for elevation):
Start-Process -Verb RunAs (Get-Process -Id $PID).Path '-Command Set-ExecutionPolicy -Force RemoteSigned'
Or: Run the Set-ExecutionPolicy
with -Scope CurrentUser
, in which case elevation is not required:
Note:
Run the following:
Set-ExecutionPolicy -Force -Scope CurrentUser RemoteSigned
Note: -Force
in the commands above suppresses the confirmation prompt that Set-ExecutionPolic
presents by default.
For a comprehensive overview of PowerShell's execution policies, see this answer.
Upvotes: 2