Welcome to the navigation

Incididunt dolor amet, aliquip nostrud ex labore quis consectetur fugiat esse dolore dolor pariatur, dolore in cupidatat in sed reprehenderit sint nulla eu ullamco voluptate. Incididunt eu lorem proident, non commodo pariatur, id eiusmod deserunt sunt ex esse ut minim ut est aliquip ad tempor dolor nisi cillum ipsum consectetur

Yeah, this will be replaced... But please enjoy the search!

Enable IIS preloadEnabled and AlwaysRunning using PowerShell

Since IIS 8 we've been able to use the built-in module "Application Initialization". It is often misunderstood how it works and that it also require an additional setting on the website instance to perform the "warm up" webadmins so often want.

It requires the Application Initialization module to be installed on the server. This can be done using the PowerShell command Install-WindowsFeature

$webAppInit = Get-WindowsFeature -Name "Web-AppInit"
Install-WindowsFeature $webAppInit -ErrorAction Stop

When you set the startMode property of your application pool to AlwaysRunning a worker process is spawned as soon as IIS starts up and does not wait for the first user request.

$site = Get-Website -Name $siteName
$appPool = Get-ChildItem IIS:\AppPools\ | Where-Object { $_.Name -eq $site.applicationPool }
$appPool | Set-ItemProperty -name "startMode" -Value "AlwaysRunning"

But this does not mean the web application is initialized.

The IIS application defaults preloadEnabled metabase setting along with the startMode setting can be used to autostart and thus warm up your web application.

Set-ItemProperty "IIS:\Sites\$siteName" -Name applicationDefaults.preloadEnabled -Value True

When you set preloadEnabled to true, IIS will simulate a user request to the default page (can be changed with initializationPage metabase setting) of the website/virdir so that the application initializes. The request is not logged in the IIS logs. (ref. https://tinyurl.com/y7qpun5j)

The entire script

### Enable if required
#Import-Module ServerManager
#Add-WindowsFeature Web-Scripting-Tools
Import-Module WebAdministration


#Set the site name
$siteName = "Default Web Site"

<#
    Enable Application Initialization
#>

#Ensure Application Initialization is available
$webAppInit = Get-WindowsFeature -Name "Web-AppInit"

if(!$webAppInit.Installed) 
{
    Write-Host "$($webAppInit.DisplayName) not present, installing"
    Install-WindowsFeature $webAppInit -ErrorAction Stop
    Write-Host "`nInstalled $($webAppInit.DisplayName)`n" -ForegroundColor Green
}
else 
{
    Write-Host "$($webAppInit.DisplayName) was already installed" -ForegroundColor Yellow
}

#Fetch the site
$site = Get-Website -Name $siteName

if(!$site)
{
    Write-Host "Site $siteName could not be found, exiting!" -ForegroundColor Yellow
    Break
}


#Fetch the application pool
$appPool = Get-ChildItem IIS:\AppPools\ | Where-Object { $_.Name -eq $site.applicationPool }


#Set up AlwaysRunning
if($appPool.startMode -ne "AlwaysRunning")
{
    Write-Host "startMode is set to $($appPool.startMode ), activating AlwaysRunning"
    
    $appPool | Set-ItemProperty -name "startMode" -Value "AlwaysRunning"
    $appPool = Get-ChildItem IIS:\AppPools\ | Where-Object { $_.Name -eq $site.applicationPool }

    Write-Host "startMode is now set to $($appPool.startMode)`n" -ForegroundColor Green
} 
else 
{
    Write-Host "startMode was already set to $($appPool.startMode) for the application pool $($site.applicationPool)" -ForegroundColor Yellow
}


<#
    Enable preloadEnabled on the IIS Site instance
#>


if(!(Get-ItemProperty "IIS:\Sites\$siteName" -Name applicationDefaults.preloadEnabled).Value) 
{
    Write-Host "preloadEnabled is inactive, activating"
    
    Set-ItemProperty "IIS:\Sites\$siteName" -Name applicationDefaults.preloadEnabled -Value True
    
    Write-Host "preloadEnabled is now set to $((Get-ItemProperty "IIS:\Sites\$siteName" -Name applicationDefaults.preloadEnabled).Value)" -ForegroundColor Green
} 
else
{
    Write-Host "preloadEnabled already active" -ForegroundColor Yellow
}

 

The process should look something like this

Or if everything is set already

Please note that this portal is a BETA site , I will continuously improve all functionality and performance during the coming weeks / the author