title: How to powershell script the IIS warm-up for asp.net 4.0?
body: <p>Can anybody please tell me how to powershell script the IIS to use the asp.net 4.0 warm-up mechanism?</p>
  
  <p>I've created this powershell script, but it doesn't seem to write anything into the applicationHost.config file:
  ( trying to implement step 3 from here, but using Powershell: <a href="http://weblogs.asp.net/gunnarpeipman/archive/2010/01/31/asp-net-4-0-how-to-use-application-warm-up-class.aspx" rel="nofollow">http://weblogs.asp.net/gunnarpeipman/archive/2010/01/31/asp-net-4-0-how-to-use-application-warm-up-class.aspx</a> )</p>
  
  <pre><code>Import-Module WebAdministration
  
  $SiteName="Default Web Site"
  $ApplicationName=“WebOne“
  
  Add-WebConfiguration "system.applicationHost/sites/site[@name='Default Web Site']/application[@path='WebOne']" -Value @{serviceAutoStartEnabled="true";serviceAutoStartProvider="PreWarmMyCache"} -PSPath IIS:\Sites\$SiteName\$ApplicationName -Location $SiteName/$ApplicationName
  </code></pre>
  
  <p>I'm trying to add these two(2) properties <code>( serviceAutoStartEnabled="true" and serviceAutoStartProvider="PreWarmMyCache"):</code></p>
  
  <p>e.g.:</p>
  
  <pre><code>&lt;application path="/" serviceAutoStartEnabled="true" serviceAutoStartProvider="PreWarmMyCache" /&gt;:
  </code></pre>
  
  <p>To my current Application Path:</p>
  
  <pre><code>&lt;sites&gt;
       &lt;site name="Default Web Site" id="1"&gt;
                  &lt;application path="/WebOne" applicationPool="ASP.NET v4.0"&gt;
                      &lt;virtualDirectory path="/" physicalPath="C:\NetProjects\WebOne" /&gt;
                  &lt;/application&gt;         
       &lt;/site&gt;
  &lt;/sites&gt;
  </code></pre>
  
  <p>I will also need to powershell script this:
  ( step 4 from here, but using Powershell: <a href="http://weblogs.asp.net/gunnarpeipman/archive/2010/01/31/asp-net-4-0-how-to-use-application-warm-up-class.aspx" rel="nofollow">http://weblogs.asp.net/gunnarpeipman/archive/2010/01/31/asp-net-4-0-how-to-use-application-warm-up-class.aspx</a> )</p>
  
  <pre><code>&lt;serviceAutoStartProviders&gt;
       &lt;add name="PreWarmMyCache" type="PreWarmCache, MyAssembly" /&gt;
  &lt;/serviceAutoStartProviders&gt;
  </code></pre>
  
  <p>Any help would be greatly appriciated.-</p>
  
  <p>I've already powershell scripted this stuff below which is also needed, but I need the stuff above ( serviceAutoStartEnabled="true" and serviceAutoStartProvider="PreWarmMyCache" ), which I mentioned.-</p>
  
  <pre><code>#Load IIS Modules
  Import-Module WebAdministration   
  
  if (Test-Path IIS:\AppPools\SosSWarmUpWorkerProcess)
  {
      #Let's delete the entry if it's already there ( while deploying between versions )
      Remove-Item IIS:\AppPools\SosSWarmUpWorkerProcess -Force -Recurse
  }
  
  $myNewPool = New-Item IIS:\AppPools\SosSWarmUpWorkerProcess  
  $myNewPool.managedRuntimeVersion = "4.0"
  $myNewPool.startMode="AlwaysRunning"
  
  $myNewPool | Set-Item
  </code></pre>