0

I need to set all times for IIS pools to be recycled each 2 minutes apart. I want to create a script in PS that would set that up for me. This is how it looks:"

$AppPool = Get-IISAppPool
$AppPoolName = $AppPool | select -ExpandProperty name

foreach ($pool in $AppPoolName) {
#Set-ItemProperty -Path IIS:\AppPools\$pool -Name recycling.periodicRestart.time -Value 3.00:00:00
}

How do I add 2min each time? -Value 3.00:00:00 -Value 3.00:02:00 -Value 3.00:04:00 etc

Dagome
  • 1

1 Answers1

1

The format to use is what a TimeSpan object outputs when using .ToString('c').

You can add 2 minutes to a TimeSpan inside the loop like

$time = New-TimeSpan -Days 3 -Hours 0 -Minutes 0 -Seconds 0

foreach ($pool in $AppPoolName) {
    Set-ItemProperty -Path IIS:\AppPools\$pool -Name recycling.periodicRestart.time -Value $time.ToString('c')
    $time = $time.Add((New-TimeSpan -Minutes 2))
}
Theo
  • 57,719
  • 8
  • 24
  • 41