Powershell App Pool sets periodic Restart syntax

I am trying to set the periodicRestart property using a powershell script, but I am trying to use a slightly different syntax than what I saw in the code samples.

Here is one way to do it according to Specify specific times for reusing the application pool using 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 set the properties for $appPool as follows:

 $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 would 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"} . The schedule property expects a hash table, which is what I pass to it.

example

Any ideas?

+4
source share
1 answer

Interestingly, you see it as [Hashtable] . I see this as [Microsoft.Iis.Powershell.Framework.ConfigurationElement] .

It has a method called .UpdateCollection() that expects [PSObject[]] , so it searches for an array of objects.

The fact is that calling this method, whether it is a pool object returned from New-WebAppPool or from Get-Item IIS:\AppPools\ExistingPool , results in an error indicating that it is read-only.

I tried to replace the entire .Collection new arraist with timespan objects added to it, and I did not get any errors, but it did not set the value.

I also tried to create a ConfigurationElement object, but it does not seem to have a constructor, so it is probably a private class somewhere in the code.

I'm not saying that there is definitely no way to do this the way you want, but it seems to you that you are best off using Set-ItemProperty , as it seems that some of these attributes were designed to be updated only through the PS Provider.

+1
source

All Articles