How to Set Application Pool (App Pool) runtime to No Managed Code using PowerShell


I was asked in another post how to set the application pool runtime to No Managed Code to run ASP pages using PowerShell. Here are the steps.

This simple PS script will loop all of the application pools on the local IIS server and output the name and the managed runtime:
Import-Module WebAdministration -ErrorAction Stop
$applicationPools = Get-ChildItem IIS:\AppPools
ForEach($appPool in $applicationPools)
{
Write-Host $appPool.name
write-host $appPool.managedRuntimeVersion
}

I manually changed the managed runtime for the .net 2.0 classic app pool to No Managed Code and ran the same code and the runtime was blank for this application pool and all other application pools displayed the correct runtime version.
Manually set the runtime back to 2.0 through Inetmgr and ran the PS script again to verify.
Through some script modifications, found that if you set the managedRuntimeVersion property for the application pool to "", it will change the drop down to No Managed Code.

Here is the full script:

Clear-Host

#Import the web administration module
Import-Module WebAdministration -ErrorAction Stop

$applicationPools = Get-ChildItem IIS:\AppPools

ForEach($appPool in $applicationPools)
{
Write-Host $appPool.name
write-host $appPool.managedRuntimeVersion

if ($appPool.name -eq ".NET v2.0 Classic")
{
$appPath = "IIS:\AppPools\"+ $appPool.name
$appPool.managedRuntimeVersion = ""
Set-ItemProperty -Path $appPath -Name managedRuntimeVersion $appPool.managedRuntimeVersion
}

}


Comments (1)

  1. Just hours before you replied to your previous post, I figured out the “Set-ItemProperty -Path -Name managedRuntimeVersion $appPool.managedRuntimeVersion” thing, but I won’t even post my solution here, as yours is much better. Thanks for the follow up!

Skip to main content