【问题标题】:Set-ItemProperty IIS:\AppPools\[App_Pool] -Name Recycling.PeriodicRestart.Time has no effect in Server 2012 R2Set-ItemProperty IIS:\AppPools\[App_Pool] -Name Recycling.PeriodicRestart.Time 在 Server 2012 R2 中无效
【发布时间】:2016-02-08 03:36:14
【问题描述】:

我有几个服务器场,一个是Server 2008 R2,一个是Server 2012 R2。经过一番搜索,我找到了以下 powershell 来禁用默认的 IIS 应用程序池回收,我在管理 powershell 提示符下运行:

Set-ItemProperty IIS:\AppPools\Test -Name Recycling.PeriodicRestart.Time -Value 0

这似乎工作正常(它在任何一个平台上都没有任何输出运行),但是当我随后尝试在Server 2008 R2 上查询该值时,我得到了这个:

PSPath                      : WebAdministration::\\SERVER1\AppPools\Test
PSParentPath                : WebAdministration::\\SERVER1\AppPools
PSChildName                 : Test
PSDrive                     : IIS
PSProvider                  : WebAdministration
IsInheritedFromDefaultValue : False
IsProtected                 : False
Name                        : time
TypeName                    : System.TimeSpan
Schema                      : Microsoft.IIs.PowerShell.Framework.ConfigurationAttributeSchema
Value                       : 00:00:00
IsExtended                  : False

但是在Server 2012 R2,我明白了:

PSPath                      : WebAdministration::\\SERVER2\AppPools\Test
PSParentPath                : WebAdministration::\\SERVER2\AppPools
PSChildName                 : Test
PSDrive                     : IIS
PSProvider                  : WebAdministration
IsInheritedFromDefaultValue : True
IsProtected                 : False
Name                        : time
TypeName                    : System.TimeSpan
Schema                      : Microsoft.IIs.PowerShell.Framework.ConfigurationAttributeSchema
Value                       : 1.05:00:00
IsExtended                  : False

请注意,第一个示例中的Value00:00:00,但在第二个示例中是1.05:00:00。这是继承自DefaultAppPool 的默认值。

我也尝试更改 DefaultAppPool 的值,但我得到了相同的结果——它适用于 2008 R2 但不适用于 2012 R2,所以我相当肯定继承不是问题。

Server 2012 R2 中是否有其他方法可以做到这一点,这样它就不会忽略命令或更好的方法——一种在Server 2008 R2Server 2012 R2 中都有效的方法?

【问题讨论】:

    标签: powershell windows-server-2012-r2


    【解决方案1】:

    呃。经过一番挫折,Set-ItemProperty 似乎是 case-sensitive,尽管 Get-ItemProperty 不是。对于所有发现此问题的人来说,解决方案非常简单:

    Set-ItemProperty -Path "IIS:\AppPools\Test" -Name recycling.periodicRestart.time -Value 00:00:00
    

    (注意属性名称的小写字母)。在Server 2012 R2 中雪上加霜,Set-ItemProperty 在属性名称大小写与底层C:\Windows\System32\inetsrv\config\applicationHost.config 文件中正确的 XML 元素名称不完全匹配的情况下(没有双关语)默默地失败。

    【讨论】:

    • 很好的发现,这个是真正的意思。此外,我们在团队中注意到区分大小写也取决于 PowerShell 版本。在 5.0 中,Set-Item 不关心大小写,而在 5.1 中它确实如此。
    • 或者它取决于 IIS 版本。 IIS 7.5 忽略大小写。 IIS 10 没有。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-21
    • 2019-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多