我试图使用Webpipe理模块在PowerShell中编写一些IIS7安装任务。 我很擅长设置简单的属性,但是在处理configuration文件中的元素集合时遇到了一些麻烦。
作为一个直接的例子,我想让应用程序池在给定的时间表上回收,而时间表是一个时间的集合。 当我通过IISpipe理控制台进行设置时,相关的configuration部分如下所示:
<add name="CVSupportAppPool"> <recycling> <periodicRestart memory="1024" time="00:00:00"> <schedule> <clear /> <add value="03:31:00" /> </schedule> </periodicRestart> </recycling> </add>
在我的脚本中,我希望能够完成同样的事情,我有以下两行:
#clear any pre-existing schedule Clear-WebConfiguration "/system.applicationHost/applicationPools/add[@name='$($appPool.Name)']/recycling/periodicRestart/schedule" #add the new schedule Add-WebConfiguration "/system.applicationHost/applicationPools/add[@name='$($appPool.Name)']/recycling/periodicRestart/schedule" -value (New-TimeSpan -h 3 -m 31)
这几乎是一回事,但是结果XML缺less通过GUI创build的<clear/>元素,我相信这是避免inheritance任何默认值所必需的。
这种集合(带有“添加”,“删除”和“清除”元素)似乎在configuration文件中是相当标准的,但我似乎无法find任何有关如何与它们保持一致的良好文档。
而不是使用Clear-WebConfiguration,而是使用Remove-WebConfigurationProperty:
Remove-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/applicationPools/add[@name='$($appPool.Name)']/recycling/periodicRestart/schedule" -name "."
这将在<schedule>中添加<clear />节点