Title: Powershell: A positional parameter cannot be found that accepts argument “test”
Tags: powershell;cmd;parameters
Question: I'm trying to execute the following command via command line
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  Send-MailMessage -from &quot;mail.me&quot; -to &quot;mail.me&quot; -Subject &quot;PS test !&quot; -Body &quot;Hi this is a power shell mail test&quot; -SmtpServer &quot;mail.domain.com&quot;
But I'm getting the following error :
Send-MailMessage: A positional parameter cannot be found that accepts argument  « test ».
Au niveau de ligne : 1 Caractère : 17
Send-MailMessage <<<<  -from mail.me -to mail.me -Subject PS test ! -Body Hi this is a power shell mail test -SmtpServer mail.domain.com
CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.SendMailMessage
The problem is that the same command works well when directly executed in Power Shell, but without the path.
What could be the problem generating this exception ?
Comment: Isn't `Send-MailMessage` a PowerShell version 2 cmdlet?

Comment: Possible duplicate of [Positional Parameter error in powershell script](https://stackoverflow.com/questions/39407004/positional-parameter-error-in-powershell-script)

Comment: I made sure it's the same path the Power Shell console is pointing to ..

Here is the accepted answer: Use -commandand braces. Currently, you are launching powershell and passing it multiple arguments instead of asking it to execute your code.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -command "&amp; {Send-MailMessage -from "mail.me" -to "mail.me" -Subject "PS test !" -Body "Hi this is a power shell mail test" -SmtpServer "mail.domain.com"}"
I'm getting errors for the some of values you have set (characters that need to be escaped, invalid emails etc), so replaced and got this to run:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -Command "&amp; {Send-MailMessage -From russellkelly@example.org -To russellkelly@example.org -Subject "whatevs" -SmtpServer "localhost" -Body "whatevs"}"
Comment for this answer: @mounaim glad to hear it's working. `&` is the call operator - [see this StackOverflow post](https://stackoverflow.com/questions/42382951/whats-the-command-of-call-operator). The [ss64 link](https://ss64.com/ps/call.html) in the accepted answer is also useful - I would recommend script blocks as in their example to avoid issues with multiple commands down the line.
Comment for this answer: I tried this and got ( Send-MailMessage -from mail.me -to mail.me -Subject PS test ! -Body Hi this is a power shell mail test -SmtpServer mail.domain.com ) in output , without the parameters' double quotes, and the command didn't execute
Comment for this answer: I got it to work by adding the ( "& ) to the begining and replacing the double quotes by singles quotes, what & is useful for here ?
Comment for this answer: gms0ulman'0 Thank  you so much, I've been struggling with this to get it to work

Here is another answer: You need to escape double quotes in your command. Otherwise command processor strips it, and your "test" appears as parameter to Send-MailMessage.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  Send-MailMessage -from "mail.me" -to "mail.me" -Subject \"PS test !\" -Body \"Hi this is a power shell mail test\" -SmtpServer "mail.domain.com"

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2017:00:06/05/17', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<powershell><cmd><parameters>', 'Title': 'Powershell: A positional parameter cannot be found that accepts argument “test”', 'ViewCount': 23580, 'id': 44367304, 'user_AboutMe': '<p>/* <br></p>\n<ul>\n<li>Love <strong>sharing</strong> and <strong>helping</strong> others <br></li>\n<li>Never Stop <strong>Learning</strong> <br>\n*/ <br></li>\n</ul>\n', 'user_AccountId': 3393169.0, 'user_DisplayName': 'mounaim', 'user_Reputation': 1052.0, 'user_Views': 444.0, 'user_id': 2854181.0}}