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.
Related
Hello i was trying to issue some distributed erlang commands such as erl -sname/erl -name and i do not get a response.
If i put . at the end it says syntax error.
If i don't it won't return anything and it will treat it like an unfinished command.
I thought this is only for these commands but it seems there are others that will not do anything like
erl -man <module_name>.
Do i need to set something up to be able to issue erl commands.
P.S OS is Windows 10.
The erl command (with or without -sname) is simply how you run Erlang from a console window like cmd or powershell. On Windows, to get a fully working Erlang shell with command line editing etc, you need to use the special werl executable instead of erl - this is due to how Windows consoles work. Try opening a cmd or powershell windows and see how it works.
If you open the properties of the icon you have used for starting Erlang, you will see that the command it is running is werl (from the Start menu you have to use "more -> open file path" to find the actual icon first). You can edit this and add options like -sname yournodename to the command, or you can create a copy of the icon (e.g. to your desktop) and give it a more suitable name, like "My Erlang node", and then edit its options.
In our Azure Cloud Shell, Powershell mode we can't run ps1 files. Although we are doing the same asin the MS Doc.
Any Suggestions, what am I doing wrong.
PS Azure:\> dir
Directory: Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
Mode Name
---- ----
. Build_goal.ps1
. Test goal_Files.ps1
. test.ps1
Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
PS Azure:\> ./test.ps1
./test.ps1 : The term './test.ps1' 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.
At line:1 char:1
+ ./test.ps1
+ ~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (./test.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Azure:/Shared PAAS – Test/StorageAccounts/tstoweuyptobi/Files/azureshellfiles/goal0402preprod/powershell
PS Azure:\>
The example below is from Microsoft Docs.
The trick is for the shell to be open in the location that the script is saved.
This will only work if your script doesn't use libraries that are stored on your local device. You may also need to import any modules needed, e.g. AzureAD
# change to your cloud drive fileshare
cd $HOME\clouddrive
# run the script
.\helloworld.ps1
Hello World!
The default directory for Cloud Shell does not seem to allow script running. Copy the script to "$HOME\clouddrive", change to that dir, then run it from there.
I want to use get-vm command from powershell.
$my_vm = get-vm -Name MY_VM_NAME
Have error message that
The term 'get-vm' is not recognized as the name of a cmdlet, function,
script f ile, or operable program. Check the spelling of the name, or
if a path was incl uded, verify that the path is correct and try
again.
I found that I need to install Microsoft.SystemCenter.VirtualMachineManager
(how to run get-vm command on windows powershell)
Execute that:
PS C:\Windows\system32> Add-PSSnapin -Name
Microsoft.SystemCenter.VirtualMachineManager
Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.SystemCenter.VirtualMa
chineManager' is not installed on this machine.
At line:1 char:13
Do I really need to install that huge tool? I don't have enough space on my VM.
http://www.microsoft.com/en-us/download/details.aspx?id=10712
Is it another way to solve issue with get-vm?
Thanks!
You can look in to connecting to the machine that has VMM on it. You can use remoting to do this. You can find some more info about it here: http://windowsitpro.com/scripting/creating-remote-sessions-powershell-20?page=3
How to create new node? i try some like here
how to run this erlang example
and find the same in tutorial
http://www.erlang.org/doc/reference_manual/distributed.html when i write
% erl -name dilbert
my compiler behaves i forgot '.' at the end. Of course i try end, result the same.
Any ideas?
The command erl -name dilbert is not meant to be typed into the Erlang shell; it's the command you run to start a distributed node instead of plain erl.
(If you really want to turn a running node into a distributed node, you can use net_kernel:start/1, but I've never had a reason to do that except in tests.)
In Linux, you can type erl -name dilbert in the terminal.
In Windows you run it in CMD.
I'm working on creating a single command that will run mulitple things on the command line of another machine. Here is what I'm looking to do.
Use psexec to access remote machine
travel to proper directory and file
execute ant task
exit cmd
run together in one line
I can run the below command from Run to complete what I need accomplished but can't seem to get the format correct for psexec to understand it.
cmd /K cd /d D:\directory & ant & exit
I've tried appling this to the psexec example below:
psexec \\machine cmd /K cd /d D:\directory & ant & exit
When executing this it will activate the command line and travel to D:\directory but won't execute the remaining commands. Adding "" just creates more issues.
Can anyone guide me to the correct format? Or something other than psexec I can use to complete this (free options only)?
Figured it out finally after some more internet searching and trial and error. psexec needs /c to run multiple commands, but that syntax doesn't work with the setup I wrote above. I've gotten the below command to run what I need.
psexec \\machine cmd /c (^d:^ ^& cd directory^ ^& ant^)
I don't need to exit because psexec will exit itself upon completion. You can also use && to require success to continue on to the next command. Found this forum helpful
http://forum.sysinternals.com/psexec_topic318.html
And this for running psexec commands
http://ss64.com/nt/psexec.html
This works:
psexec \ComputerName cmd /c "echo hey1 & echo hey2"
For simple cases I use:
PsExec \\machine <options> CMD /C "command_1 & command_2 & ... & command_N"
For more complex cases, using a batch file with PsExec's -c switch may be more suitable:
The -c switch directs PsExec to copy the specified executable to the remote system for execution and delete the executable from the remote system when the program has finished running.
PsExec \\machine <options> -c PSEXEC_COMMANDS.cmd <arguments>
Since you asked about other options and this has tag configuration managment-- I guess you may be interested in Jenkins (or Hudson). It provide very good way of creating master-slave mechanism which may help in simplifying the build process.
I always use like this way :) and works properly
psexec \\COMPUTER -e cmd /c (COMMAND1 ^& COMMAND2 ^& COMMAND3)