我正在尝试使用powershell脚本设置periodicRestart
属性,但我尝试使用的语法与我在代码示例中看到的略有不同。
根据Set the specific times to recycle an application pool with PowerShell,这是一种方法:
Clear-ItemProperty $iisAppPoolName -Name Recycling.periodicRestart.schedule
Set-ItemProperty $iisAppPoolName -Name Recycling.periodicRestart.schedule `
-Value @{value="01:00:00"}
但是,我已经有一段代码,我在$appPool
本身设置属性,如下所示:
$appPool = New-WebAppPool $iisAppPoolName
$appPool.managedPipelineMode = "Classic"
$appPool.managedRuntimeVersion = "c4.0"
$appPool.recycling.periodicRestart.time = [TimeSpan]"00:00:00"
$appPool | Set-Item
哪个工作正常,所以我想添加以下行:
$appPool.recycling.periodicRestart.schedule = @{value="01:00:00"}
但是我无法获得@{value="01:00:00"}
的语法。 schedule
属性期待一个哈希表,这就是我传递的内容。
有什么想法吗?
答案 0 :(得分:3)
有趣的是,您将其视为[Hashtable]
。我将其视为[Microsoft.Iis.Powershell.Framework.ConfigurationElement]
。
它有一个名为.UpdateCollection()
的方法,它需要[PSObject[]]
,所以它正在寻找一个对象数组。
问题是,调用该方法,无论是从New-WebAppPool
还是从Get-Item IIS:\AppPools\ExistingPool
返回的池对象,都会导致错误,指出它是只读的。
我尝试用添加了timepan对象的新arraylist替换整个.Collection
,但我没有错误,但没有设置值。
我也尝试过创建一个ConfigurationElement对象,但似乎没有构造函数,所以它可能是代码中某处的私有类。
我并不是说绝对没有办法按照你的意愿去做,但看起来你最好只使用Set-ItemProperty
,因为看起来其中一些属性设计为仅通过PS提供程序进行更新。