I am creating a function to manage App Pools in IIS7 to our desired specifications, and I am having trouble converting one line from our equivalent IIS6 script; to set the restart schedule.
In IIS6 the line was:
$newPool.PeriodicRestartSchedule = @( '6:15' );
The naive translation for IIS7 is:
$newPool.Recycling.PeriodicRestart.Schedule = @('00000000061500.000000:000')
however this doesn’t work because it throws the exception:
Exception setting "Schedule": "Unable to cast object of type 'System.String'
to type 'System.Management.ManagementBaseObject'.
How do I create this ScheduleElement[] array to assign to this value?
Edit: problem 1 down…:
$time = ([wmiclass]'root\WebAdministration:ScheduleElement').CreateInstance()
$time.Value = '00000000061500.000000:000'
$newPool.Recycling.PeriodicRestart.Schedule = $time;
Problem 2: This value doesn’t seem to save when I call $newPool.Put(). What’s next?
I’ve given up and decided to use appcmd:
I am still interested in seeing how this can be done without appcmd.