title: Setting app pools to recycle at multiple specific times via powershell or appcmd does not display both times in GUI/IIS
body: <p>I am attempting to set app pools to recycle at multiple times in the day in iis 8.5, I've tried using powershell and app command and when testing on a server that has no sites/applications in the pool it seems to work perfectly, however when trying to set using either method on a server that has sites in the app pools I'm seeing strange behavior, It seems to work however in the GUI of IIS if i look at the recycling settings of the app pool it only shows one of the times specified. 
  Powershell script initially tried using is: </p>
  
  <pre><code>function Set-ApplicationPoolRecycleTimes {
      param (
          [string]$ApplicationPoolName,
          [string[]]$RestartTimes
      )
      Import-Module WebAdministration
      Write-Output "Updating recycle times for $ApplicationPoolName"
      # Delete all existing recycle times
      Clear-ItemProperty IIS:\AppPools\$ApplicationPoolName -Name Recycling.periodicRestart.schedule    
      Clear-ItemProperty IIS:\AppPools\$ApplicationPoolName -Name Recycling.periodicRestart.time
      foreach ($restartTime in $RestartTimes) {
          Write-Output "Adding recycle at $restartTime"
          # Set the application pool to restart at the time we want
          New-ItemProperty -Path "IIS:\AppPools\$ApplicationPoolName" -Name Recycling.periodicRestart.schedule -Value @{value=$restartTime}
          Set-ItemProperty -Path "IIS:\AppPools\$ApplicationPoolName" -Name Recycling.periodicRestart.time -Value "00:00:00"
      } # End foreach restarttime
  } # End function Set-ApplicationPoolRecycleTimes
  $apppoolname1 = "app pool's name"
  $restartat = @("1:45", "18:45")
  Set-ApplicationPoolRecycleTimes -ApplicationPoolName $apppoolname1 -RestartTimes $restartat
  </code></pre>
  
  <p>Again this seems to work perfectly unless there are sites in the application pool.  When sites exist it seems to work except that the gui only shows one of the times set:
  <a href="https://i.stack.imgur.com/Yrrdd.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yrrdd.jpg" alt="enter image description here"></a></p>
  
  <p>however querying the value show's both times: </p>
  
  <pre><code>Import-Module WebAdministration
  (Get-ItemProperty ('IIS:\AppPools\app pool name') -Name Recycling.periodicRestart.schedule.collection) | select value
  
  value   
  -----   
  18:45:00
  01:45:00
  </code></pre>
  
  <p>also attempted using appcmd but finding the same results, works perfectly on a server with no sites in the app pool, but when run against servers with sites, missing one of the times in the gui, querying shows both times.  I have turned logging on for app pool recycles to confirm it's happening at both times but wondering if I'm just overlooking something obvious.</p>
  
  <p>appcmd script:</p>
  
  <pre><code>CD C:\windows\System32\inetsrv
  $V1 = "app pool name"
  #clears any existing schedule
  cmd.exe /c appcmd.exe set apppool /apppool.name: $V1 /-recycling.periodicRestart.schedule
  #setting desired recycles 
  cmd.exe /c appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='$v1'].recycling.periodicRestart.schedule.[value='01:45:00']" /commit:apphost
  cmd.exe /c appcmd.exe set config -section:system.applicationHost/applicationPools /+"[name='$v1'].recycling.periodicRestart.schedule.[value='18:45:00']" /commit:apphost
  </code></pre>