0

我正在编写一个任务来定期远程重启一些服务器应用程序池。我正在使用 Invoke-Command 如下:

Invoke-Command -ComputerName $server {Restart-WebItem "IIS:\AppPools\DefaultAppPool"}

这很好用;但是,如果我将应用程序池参数化如下

$appPool = "IIS:\AppPools\DefaultAppPool"
Invoke-Command -ComputerName $server {Restart-WebItem $appPool}

它失败了

Unexpected object type.
Parameter name: pspath

我认为这只是一个语法问题,但我不知道是什么。

4

1 回答 1

1

远程主机上的 $appPool 将不存在。如果您使用的是 PS V3,您可以在变量前面加上using:关键字 ->

$appPool = "IIS:\AppPools\DefaultAppPool"
Invoke-Command -ComputerName $server {Restart-WebItem $using:appPool}

在版本 3 之前,您必须使用-argumentList参数

于 2014-09-19T13:02:31.680 回答