如何设置IIS应用程序池回收时间,而不使用丑陋的Add-WebConfiguration语法?

我一直脚本编写我们的IIS 7.5实例的configuration,并通过其他人民的脚本的脚本我已经想出了一个我喜欢的语法:

$WebAppPoolUserName = "domain\user" $WebAppPoolPassword = "password" $WebAppPoolNames = @("Test","Test2") ForEach ($WebAppPoolName in $WebAppPoolNames ) { $WebAppPool = New-WebAppPool -Name $WebAppPoolName $WebAppPool.processModel.identityType = "SpecificUser" $WebAppPool.processModel.username = $WebAppPoolUserName $WebAppPool.processModel.password = $WebAppPoolPassword $WebAppPool.managedPipelineMode = "Classic" $WebAppPool.managedRuntimeVersion = "v4.0" $WebAppPool | set-item } 

我已经看到这样做了很多不同的方式,不那么简洁,我喜欢这种设置对象属性的语法看起来比较像我在TechNet上看到的东西:

 Set-ItemProperty 'IIS:\AppPools\DemoPool' -Name recycling.periodicRestart.requests -Value 100000 

有一件事我没有弄清楚,但是如何使用这个语法设置回收计划。

这个命令设置ApplicationPoolDefaults,但是很丑陋:

 add-webconfiguration system.applicationHost/applicationPools/applicationPoolDefaults/recycling/periodicRestart/schedule -value (New-TimeSpan -h 1 -m 30) 

我已经通过appcmd使用类似以下的东西,但我真的想通过PowerShell完成这一切:

 %appcmd% set apppool "BusinessUserApps" /+recycling.periodicRestart.schedule.[value='01:00:00'] 

我努力了:

 $WebAppPool.recycling.periodicRestart.schedule = (New-TimeSpan -h 1 -m 30) 

这具有将.schedule属性转换为时间范围的奇怪效果,直到我使用$ WebAppPool = get-item iis:\ AppPools \ AppPoolName来刷新variables。

还有$WebappPool.recycling.periodicRestart.schedule.Collection但集合上没有add()函数,我还没有find任何其他方法来修改它。

有谁知道一种方法,我可以使用与我上面写的代码一致的语法来设置预定的回收时间?

我永远不知道如何设置对象本身,但创build它后,以下工作:

 clear-ItemProperty IIS:\AppPools\MyPoolName -Name Recycling.periodicRestart.schedule #clear values set-ItemProperty IIS:\AppPools\MyAppPoolName -Name Recycling.periodicRestart.schedule -Value @{value="00:00:00"} #to set it to midnight 

所以不只是

 $webapppool.recycling.periodicrestart.schedule -Value "01:30:00" 

然后? 还是相当于TimeSpan的ToString?

(我不PowerShell;只是基于你的其他位语法猜测)。