如何使用CMD系列在PowerShell的远程计算机上重新启动IIS应用程序池?

发布于 2025-02-05 08:43:39 字数 772 浏览 2 评论 0原文

我已经尝试在远程计算机上自动回收IIS AppPool。我有99%的脚本正常工作,除了我坚持回收/重新启动远程服务器上的应用程序池。

当我运行以下命令时:

Invoke-Command -ComputerName dwintvs  -ScriptBlock {Invoke-Expression -Command:"%windir%\system32\inetsrv\appcmd" ("&") start APPPOOL "ProAPI"}

我不断出现错误:

A positional parameter cannot be found that accepts argument 'start'.
    + CategoryInfo          : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand
    + PSComputerName        : dwintvs 

如果尝试重新启动或停止,我会遇到相同的错误。

有人想念我想念什么吗?

我还尝试了|&,但我会遇到更多错误。

I've trying to automate recycling the IIS AppPool on a remote machine. I've got 99% of the script working, except I'm stuck at recycling/restarting the app pool on the remote server.

When I run the following command:

Invoke-Command -ComputerName dwintvs  -ScriptBlock {Invoke-Expression -Command:"%windir%\system32\inetsrv\appcmd" ("&") start APPPOOL "ProAPI"}

I keep getting the error:

A positional parameter cannot be found that accepts argument 'start'.
    + CategoryInfo          : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand
    + PSComputerName        : dwintvs 

I get the same error if I try a restart or stop.

Any thoughts anyone what I'm missing?

I also tried the | and & but I get more errors.

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

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

发布评论

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

评论(1

独﹏钓一江月 2025-02-12 08:43:39

通过PS 5.1在服务器2019上测试,

我所做的只是稍微清理命令行。

这不需要 WebAdministration 模块,因为它使用了经典的IIS管理实用程序:

Invoke-Command -ComputerName dwintvs -ScriptBlock { c:\windows\system32\inetsrv\appcmd start APPPOOL "ProAPI" }

请注意,我无法在其中获取环境变量,因此硬编码通往 appcmd

Tested on Server 2019 with PS 5.1

All I did is cleaning up the command line a little bit.

This does not require webadministration module as it uses the classic IIS management utility:

Invoke-Command -ComputerName dwintvs -ScriptBlock { c:\windows\system32\inetsrv\appcmd start APPPOOL "ProAPI" }

Note I was not able to get an environment variable in there so hardcoding the path to appcmd

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文