How do I set the .NET Framework Version when using New-WebAppPool? How do I set the .NET Framework Version when using New-WebAppPool? powershell powershell

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


Alternatively, you can set this the on the return value from the New-WebAppPool cmdlet. This approach can be useful if you want to change other properties as well.

For the v4.0 pool it'll look like this:

Import-Module WebAdministration$appPool = New-WebAppPool -Name Pool1$appPool.managedRuntimeVersion = "v4.0"$appPool | Set-Item

To set it to 'No managed code' you can use this:

Import-Module WebAdministration$appPool = New-WebAppPool -Name Pool2$appPool.managedRuntimeVersion = ""$appPool | Set-Item