Invoke-Item cmdlet 可以启动带有参数的可执行文件吗?

发布于 2024-09-16 03:50:43 字数 344 浏览 1 评论 0原文

我尝试使用 PowerShell 安装一些自定义 Windows 服务,但无法运行 InstallUtil,但会出现以下错误:

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

这是我运行的导致上述错误的内容:

Invoke-Command -ComputerName <remote machine> -ScriptBlock {Invoke-Item C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "<path to service exe>"}

I'm trying to install some custom Windows services using PowerShell, and I've been unable to run InstallUtil without getting the following error:

A positional parameter cannot be found that accepts argument ''

Here's what I've run that causes the error above:

Invoke-Command -ComputerName <remote machine> -ScriptBlock {Invoke-Item C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "<path to service exe>"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七颜 2024-09-23 03:50:43

来自文档:

Invoke-Item cmdlet 对指定项目执行默认操作。

我不相信命令行参数可以与默认操作一起使用。

但是...

在此示例中,调用可执行文件不需要 invoke-item。

Invoke-Command -ComputerName <remote machine> -ScriptBlock { C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "<path to service exe>"}

From the docs:

The Invoke-Item cmdlet performs the default action on the specified item.

I don't believe commandline arguments can be used with a default action.

However...

In this example, invoke-item shouldn't be necessary to invoke the executable.

Invoke-Command -ComputerName <remote machine> -ScriptBlock { C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe "<path to service exe>"}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文