gpt4 book ai didi

Powershell:找不到接受参数 “test”的位置参数

转载 作者:行者123 更新时间:2023-12-02 16:22:01 25 4
gpt4 key购买 nike

我正在尝试通过命令行执行以下命令

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"

但我收到以下错误:

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

问题是,在 Power Shell 中直接执行相同的命令但没有路径时效果很好。

产生此异常的问题可能是什么?

最佳答案

使用-命令和大括号。目前,您正在启动 powershell 并向其传递多个参数,而不是要求它执行您的代码。

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -command "& {Send-MailMessage -from "mail.me" -to "mail.me" -Subject "PS test !" -Body "Hi this is a power shell mail test" -SmtpServer "mail.domain.com"}"

我收到了您设置的一些值的错误(需要转义的字符、无效的电子邮件等),因此进行替换并使其运行:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe  -Command "& {Send-MailMessage -From test@test.com -To othertest@test.com -Subject "whatevs" -SmtpServer "localhost" -Body "whatevs"}"

关于Powershell:找不到接受参数 “test”的位置参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44367304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com