如何使用CMD系列在PowerShell的远程计算机上重新启动IIS应用程序池?
我已经尝试在远程计算机上自动回收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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过PS 5.1在服务器2019上测试,
我所做的只是稍微清理命令行。
这不需要 WebAdministration 模块,因为它使用了经典的IIS管理实用程序:
请注意,我无法在其中获取环境变量,因此硬编码通往 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:
Note I was not able to get an environment variable in there so hardcoding the path to appcmd