powershell - Set-ItemProperty IIS :\AppPools\[App_Pool] -Name Recycling. PeriodicRestart.Time 在 Server 2012 R2 中无效

标签 powershell windows-server-2012-r2

我有几个服务器场,一个是 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

请注意 Value在第一个例子中是 00:00:00 ,但在第二个例子中是 1.05:00:00 .这是从 DefaultAppPool 继承的默认值.

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

Server 2012 R2 中是否有其他方法可以做到这一点以便它不会忽略命令或更好的方法——一种在 Server 2008 R2 中都有效的方法和 Server 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 元素名称不完全匹配的情况下(无双关语),静默失败文件。

关于powershell - Set-ItemProperty IIS :\AppPools\[App_Pool] -Name Recycling. PeriodicRestart.Time 在 Server 2012 R2 中无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33576111/

相关文章:

powershell - 恶意软件使用 .Lnk 文件到 Powershell

tomcat - 安全的 Websocket 连接(wss :) abort in tomcat/spring,,而 https 正在工作

python - 在 Visual Studio Team Services 构建过程中 AWS CLI 安装在哪里

node.js - 在 IIS 中部署 Node 应用程序

ssl - URL 应该点击 https 而不是 http

powershell - 如何在管道中处理$ null

json - 使用 PowerShell 如何在具有注释的 json 文件中替换和保存值

powershell - 如何使用 PowerShell 强制删除打开的文件

powershell - 如何使powershell内联脚本路径识别空格?

centos - 迁移 VMWare 镜像到 KVM