Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Term '-Execution Policy' is not recognized

Tags:

powershell

I would like to run such a statement in powershell:

-ExecutionPolicy Bypass -File install-sshd.ps1

But I get this error message:

-ExecutionPolicy : The term '-ExecutionPolicy' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

What should I do do to solve this issue? Many thanks

like image 433
Kaja Avatar asked Jan 08 '18 10:01

Kaja


2 Answers

You need to put "PowerShell" in front of that:

PowerShell -ExecutionPolicy Bypass -File install-sshd.ps1

-ExecutionPolicy is a parameter of the PowerShell .exe.

like image 188
Mark Wragg Avatar answered Oct 16 '22 14:10

Mark Wragg


As for.. . "Sorry, I am really new in PowerShel world. What is typo? – Kaja"

Please watch this series https://www.youtube.com/results?search_query=beginning+powershell

If you are in the cmd prompt or any other cmd terminal, you do this..

powershell.exe -ExecutionPolicy Bypass "D:\Scripts\Script.ps1"

If you are already in the PowerShell console, or the PowerShell-ise.exe, you do this

Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
D:\Scripts\Script.ps1

It is technically not possible for you to get this error... "The term '-ExecutionPolicy' is not recognized as the name of a cmdlet, function, script file, or operable program." ...unless you are not typing this correctly '-ExecutionPolicy' is only usable as a parameter after the powershell.exe or powershell_ise.exe executable.

Get-ExecutionPolicy
(Get-Command -Name Get-ExecutionPolicy).Parameters
Get-help -Name Get-ExecutionPolicy -Examples
Get-help -Name Get-ExecutionPolicy -Full
Get-help -Name Get-ExecutionPolicy -Online

(Get-Command -Name Set-ExecutionPolicy).Parameters
Get-help -Name Set-ExecutionPolicy -Examples
Get-help -Name Set-ExecutionPolicy -Full
Get-help -Name Set-ExecutionPolicy -Online

Please try and copy one of the examples to attempt a run.

If you are doing this in an enterprise environment, and they have by policy disabled PowerShell on you machine or blocked this cmdlet use, then you'll not be able to use it.

like image 29
postanote Avatar answered Oct 16 '22 15:10

postanote