2015-11-06 27 views
4

我有幾個服務器場,其中一個服務器爲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中都可以使用的方法?

回答

5

呃。經過很多挫折後,看起來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沒有。 –

相關問題