Set-ItemProperty IIS:\ AppPools \ [App_Pool] -Name Recycling.PeriodicRestart.Time在服务器2012 R2中没有任何作用

问题描述:

我有几个服务器场,其中一个服务器为Server 2008 R2,另一个服务器为Server 2012 R2。一堆搜索后,我发现下面的PowerShell来禁用默认的IIS应用程序池回收,这是我在行政PowerShell提示符下运行:Set-ItemProperty IIS: AppPools [App_Pool] -Name Recycling.PeriodicRestart.Time在服务器2012 R2中没有任何作用

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中都可以使用的方法?

呃。经过很多挫折后,看起来Set-ItemPropertycase-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元素名称不完全匹配。

+0

不错的发现,这是一个真正的意思。另外我们注意到在我们的团队中,区分大小写还取决于PowerShell版本。在5.0中,'Set-Item'不关心大小写,它在'5.1'中。 –

+0

或者它取决于IIS版本。 IIS 7.5忽略大小写。 IIS 10没有。 –