I'm trying to set the periodicRestart
property using a powershell script, but I'm trying to use a slightly different syntax than what I've seen in code samples.
Here's one way to do according to Set the specific times to recycle an application pool with PowerShell:
Clear-ItemProperty $iisAppPoolName -Name Recycling.periodicRestart.schedule
Set-ItemProperty $iisAppPoolName -Name Recycling.periodicRestart.schedule `
-Value @{value="01:00:00"}
However, I already have a block of code where I'm setting properties on the $appPool
itself like this:
$appPool = New-WebAppPool $iisAppPoolName
$appPool.managedPipelineMode = "Classic"
$appPool.managedRuntimeVersion = "c4.0"
$appPool.recycling.periodicRestart.time = [TimeSpan]"00:00:00"
$appPool | Set-Item
Which works fine, so I'd like to add the following line:
$appPool.recycling.periodicRestart.schedule = @{value="01:00:00"}
But I can't get the syntax for @{value="01:00:00"}
to take. The schedule
property is expecting a hashtable which is what I'm passing it.
Any ideas?
In the pop up "Edit Application Pool Recycling Settings" window, change the recycling settings from a “Regular time intervals” to “Specific time(s)” and choose a time with the least amount of user impact. NOTE: Be sure the “Regular time intervals” box is no longer checked as show below. 6. Click “Next”.
Configuring Auto-Start with IIS ManagerIn the Connections pane, select the Application Pools node, revealing the Application Pools pane in the main view. Select the application pool for which you wish to enable Auto-Start. Locate the Start Mode option under the General group and set it to AlwaysRunning. Click OK.
Select a file or directory. Click the Locations button and make sure that you select your computer. Enter IIS AppPool\DefaultAppPool in the Enter the object names to select: text box. Click the Check Names button and click OK.
It's interesting that you're seeing it as a [Hashtable]
. I see it as a [Microsoft.Iis.Powershell.Framework.ConfigurationElement]
.
It has a method called .UpdateCollection()
which expects a [PSObject[]]
, so it's looking for an array of objects.
The thing is, calling that method, whether on a pool object returned from New-WebAppPool
or from Get-Item IIS:\AppPools\ExistingPool
, results in an error stating that it's read only.
I tried replacing the entire .Collection
with a new arraylist with timespan objects added to it, and I got no errors, but it didn't set the values.
I also tried creating a ConfigurationElement object, but it seems to have no constructor, so it's probably a private class somewhere in the code.
I'm not saying there's definitely no way to do it like you want, but it seems like you'll be best off just using Set-ItemProperty
as it seems that some of these attributes were designed to be updated only through the PS Provider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With