Powershell脚本更改应用程序池上的回收时间
-
26-12-2019 - |
题
我找到了我认为我需要使用的代码,但问题是它不起作用。
Import-Module WebAdministration
$appPools = Get-childItem 'IIS:\AppPools\App Pool'
Set-ItemProperty -Path $appPools -Name recycling.periodicRestart.time -Value 1.00:00:00
但我得到这个错误
Set-ItemProperty : Cannot find path 'C:\Windows\SysWOW64\WindowsPowerShell\v1.0\Modules\WebAdministration\Microsoft.IIs.PowerShell.Framework.NodeCollection' because it does not exist.
At line:3 char:1
+ Set-ItemProperty -Path $appPools -Name recycling.periodicRestart.time -Value 1.0 ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (C:\Windows\SysW....NodeCollection:String) [Set-ItemProperty], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand
我知道这不是路径问题。这确实有效。
set-itemproperty -path 'D:\test\TestPS\New Text.txt' -name IsReadOnly -value $true
任何帮助将是巨大的。..
解决方案
它 是 一个路径问题。
从返回的对象 Get-ChildItem 'IIS:\AppPools\App Pool'
是一个 NodeCollection
对象,并且当您运行 Set-ItemProperty -Path $appPools
, $appPools
被扩展为"微软。IIs。PowerShell的。框架。NodeCollection"(不是有效路径)
更改应用程序池的属性:
Set-ItemProperty -Path 'IIS:\AppPools\App Pool' -Name recycling.periodicRestart.time -Value 1.00:00:00
不隶属于 StackOverflow