When I type iex -S mix
in PowerShell I get this error:
Invoke-Expression : A positional parameter cannot be found that accepts argument 'mix'.
At line:1 char:1
+ iex S mix
+ ~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand
What is the correct way to write the '-S mix' after the 'iex' command to get the same effect typing it in cmd would do? This is an issue with me not understanding PowerShell syntax I believe.
The problem is that iex
is an alias in Powershell, short for Invoke-Expression
. If you're trying to run a command iex.exe
, iex.bat
or iex.cmd
, you'll have to specify it in some unique way: an explicit (or full) path, or even just adding the application's extension may be enough. That way, Powershell won't try to run Invoke-Expression
.
Get-Command
can clear this sort of thing up for you:
PS C:\Dir> Get-Command iex
CommandType Name ModuleName
----------- ---- ----------
Alias iex -> Invoke-Expression
PS C:\Dir> Get-Command cmd
CommandType Name ModuleName
----------- ---- ----------
Application cmd.exe
It doesn't seem to be possible to list both the command type and path at the same time: if you want to see which iex
is which, you can use this form:
PS C:\Dir> Get-Command -All iex -Syntax
Invoke-Expression
C:\windows\iex.bat
You can find out more about how Powershell decides which command to run in Microsoft's technet library.
For anyone else who may see this question:
Short answer--to run iex from within Powershell type iex.bat
. In this particular case iex.bat -S mix
If you use Elixir across different platforms and don't need yet another source of inconsistency (such as needing to remember use iex.bat
instead of iex
) you can remove the Invoke-Expression
alias like so:
Remove-Item alias:\iex -Force
Now you can iex -S mix
or whatever to your heart's content. Just be aware that this can conflict with other scripts you might run which assume iex
is aliasing Invoke-Expression
. For example I've had problems with the Azure SDK when un-binding iex
, but I don't do Elixir and Azure dev on the same machine any more and I haven't run into any other issues yet.
If you want to have this happen automatically, add it to your Powershell profile. Easiest way is running notepad $PROFILE
from Powershell and then add Remove-Item alias:\iex -Force
near the end of your profile script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With