我正在放置一个Powershell脚本,将在清晨计划的时间回收所有当前正在运行的AppPools。现在,我只是试图让它在本地机器上工作,并且出现错误“无法验证参数名称参数”,参数为空。“重新启动WebAppPool使用foreach失败
# Load IIS module:
Import-Module WebAdministration
# Get pool names:
$poolList = (Get-ChildItem -Path IIS:\AppPools | Where {$_.State -eq
"Started"} | Select -ExpandProperty Name)
# Recycle Web App Pools
foreach ($item in $poolList)
{
Write-Host "Processing" $item -ForegroundColor Green
Invoke-Command -ComputerName localhost -ScriptBlock {Restart-WebAppPool -
Name $item}
}
当我运行脚本时,它循环遍历每个AppPool项目。我看到用这条线......
Write-Host "Processing" $item -ForegroundColor Green
...但是Invoke-Command说参数'Name'是空的。我确信我错过了一些简单的东西,但不知道它是什么。
在此先感谢您的帮助。
的可能的复制[Powershell的调用命令与变量的脚本名称](https://stackoverflow.com/questions/11738227/powershell-invoke-command-with-variable-for-script-name ) – TessellatingHeckler