Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm trying to script some IIS7 setup tasks in PowerShell using the WebAdministration module. I'm good with setting simple properties, but am having some trouble when it comes to dealing with collections of elements in the config files.

As an immediate, example, I want to have application pools recycle on a given schedule, and the schedule is a collection of times. When I set this up via the IIS management console, the relevant config section looks like this:

<add name="CVSupportAppPool">
    <recycling>
        <periodicRestart memory="1024" time="00:00:00">
            <schedule>
                <clear />
                <add value="03:31:00" />
            </schedule>
        </periodicRestart>
    </recycling>
</add>

In my script I would like to be able to accomplish the same thing, and I have the following two lines:

#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)

That does almost the same thing, but the resulting XML lacks the <clear/> element that is created with via the GUI, which I believe is necessary to avoid inheriting any default values.

This sort of collection (with "add", "remove", and "clear" elements) seems to be fairly standard in the config files, but I can't seem to find any good documentation on how to interact with them consistently.

share|improve this question
    
Did you ever get an answer to this? You could just use an XmlPoke I suppose, if you have privilege to do that. –  jcolebrand Aug 27 '12 at 20:49

1 Answer 1

Rather than using Clear-WebConfiguration, use Remove-WebConfigurationProperty instead:

Remove-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/applicationPools/add[@name='$($appPool.Name)']/recycling/periodicRestart/schedule" -name "."

This will add the <clear /> node inside <schedule>

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.