How do I set the .NET Framework Version when using New-WebAppPool?
With the WebAdministration module loaded try this on a pool that you've created:
Set-ItemProperty IIS:\AppPools\<pool_name> managedRuntimeVersion v4.0
Import-Module WebAdministration
#Get all web sites
dir IIS:\Sites | ForEach-Object {
#Go to the app pools root
cd IIS:\AppPools\
if (!(Test-Path $_.Name -pathType container))
{
#Create the app pool and set .net framework version
$appPool = New-Item $_.Name
$appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $IISAppPoolDotNetVersion
#Go to the web sites root
cd IIS:\Sites\
$iisApp = Get-Item $_.Name
$iisApp | Set-ItemProperty -Name "applicationPool" -Value $_.Name
}
else {
$dotNetVersion = (Get-ItemProperty $_.Name managedRuntimeVersion).Value
if ($dotNetVersion -ne $IISAppPoolDotNetVersion){
#Get the app pool and set .net framework version
$appPool = Get-Item $_.Name
$appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $IISAppPoolDotNetVersion
}
}
}
You can download detail script from how to set the IIS Application Pool to specify version of the .NET Framework