代码之家  ›  专栏  ›  技术社区  ›  KyleMit Steven Vachon

Powershell应用程序池设置periodicRestart语法

  •  7
  • KyleMit Steven Vachon  · 技术社区  · 9 年前

    我正在尝试设置 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 属性需要一个哈希表,这就是我传递给它的内容。

    example

    有什么想法吗?

    1 回复  |  直到 9 年前
        1
  •  3
  •   briantist    9 年前

    有趣的是,你将其视为 [Hashtable] 。我认为这是 [Microsoft.Iis.Powershell.Framework.ConfigurationElement] .

    它有一个名为 .UpdateCollection() 它需要 [PSObject[]] ,所以它在寻找一个对象数组。

    问题是,无论是在从 New-WebAppPool 或来自 Get-Item IIS:\AppPools\ExistingPool ,导致一个错误,说明它是只读的。

    我试着更换整个 .Collection 添加了一个新的数组列表,其中添加了时间跨度对象,我没有收到任何错误,但它没有设置值。

    我还尝试创建了ConfigurationElement对象,但它似乎没有构造函数,所以它可能是代码中的某个私有类。

    我不是说有 绝对不行 想做什么就做什么,但似乎你最好只使用 Set-ItemProperty 因为似乎这些属性中的一些被设计为仅通过PS提供商进行更新。