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

前端 未结 3 1697
长情又很酷
长情又很酷 2020-12-29 02:06

I\'m looking to see how I can use the IIS PowerShell Cmdlet New-WebAppPool to specify the version of the .NET Framework to use. Currently, it defaults to v

相关标签:
3条回答
  • 2020-12-29 02:30
    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

    0 讨论(0)
  • 2020-12-29 02:35

    With the WebAdministration module loaded try this on a pool that you've created:

    Set-ItemProperty IIS:\AppPools\<pool_name> managedRuntimeVersion v4.0
    
    0 讨论(0)
  • 2020-12-29 02:51

    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
    
    0 讨论(0)
提交回复
热议问题