How to powershell script the IIS warm-up for asp.net 4.0 ?RSS

1 reply

Last post Dec 23, 2017 12:26 AM by AnimeNerd

  • How to powershell script the IIS warm-up for asp.net 4.0 ?

    Jun 14, 2011 07:38 AM|LordSmacker|LINK

    Hi there,

    Can anybody please tell me how to powershell script the IIS to use the asp.net 4.0 warm-up mechanism?

    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: http://weblogs.asp.net/gunnarpeipman/archive/2010/01/31/asp-net-4-0-how-to-use-application-warm-up-class.aspx )

    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


    I'm trying to add these two(2) properties ( serviceAutoStartEnabled="true" and serviceAutoStartProvider="PreWarmMyCache"):

    e.g.:
    <application path="/" serviceAutoStartEnabled="true" serviceAutoStartProvider="PreWarmMyCache" />:

    To my current Application Path:

    <sites>
         <site name="Default Web Site" id="1">

                    <application path="/WebOne" applicationPool="ASP.NET v4.0">
                        <virtualDirectory path="/" physicalPath="C:\NetProjects\WebOne" />
                    </application>         
         </site>
    </sites>


    I will also need to powershell script this:
    ( step 4 from here, but using Powershell: http://weblogs.asp.net/gunnarpeipman/archive/2010/01/31/asp-net-4-0-how-to-use-application-warm-up-class.aspx )

    <serviceAutoStartProviders>
         <add name="PreWarmMyCache" type="PreWarmCache, MyAssembly" />
    </serviceAutoStartProviders>


    Any help would be greatly appriciated.-

    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.-

    #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

  • Re: How to powershell script the IIS warm-up for asp.net 4.0 ?

    Dec 23, 2017 12:26 AM|AnimeNerd|LINK

    This worked for me:

    Set-WebConfigurationProperty -Filter "system.applicationHost/sites/site[@name='$WebSiteName']/application[@path='/']" -Name serviceAutoStartEnabled -Value True
    Set-WebConfigurationProperty -Filter "system.applicationHost/sites/site[@name='$WebSiteName']/application[@path='/']" -Name serviceAutoStartProvider -Value "YourApplicationPreload"