简体   繁体   English

PowerShell获取站点正在IIS中运行的.NET Framework版本

[英]PowerShell to get .NET framework version that a site is running in IIS

Is there a way to use PowerShell to get the .NET framework that a web application is running on in IIS? 有没有一种方法可以使用PowerShell来获取Web应用程序在IIS中运行的.NET框架?

I have been able to use the following to get the website name and to see that the app pool is set up as "Clr4IntegratedAppPool," but I am not seeing a way to determine what version of .NET the site itself is running. 我已经能够使用以下命令获取网站名称,并看到应用程序池已设置为“ Clr4IntegratedAppPool”,但是我没有找到一种方法来确定网站本身正在运行的.NET版本。

To clarify, I am trying to get the .NET version of the site itself, not the app pool. 为澄清起见,我正在尝试获取网站本身的.NET版本,而不是应用程序池。 For example if Site1 is running version 4.6.2 under AppPool1 (which is set to 4.0) then I am trying to get to the 4.6.2. 例如,如果Site1在AppPool1(设置为4.0)下运行4.6.2版本,那么我正在尝试进入4.6.2。

[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")

$sm = New-Object Microsoft.Web.Administration.ServerManager

foreach($site in $sm.Sites)
{
    $root = $site.Applications | where { $_.Path -eq "/" }
    Write-Output ("Site: " + $site.Name + " | Pool: " + $root.ApplicationPoolName )
}

Here is a way to do it 这是一种方法

$myServer = "name of server"

$IIS = [Microsoft.Web.Administration.ServerManager]::OpenRemote($myServer)

foreach ($pool in $IIS.ApplicationPools)
{
    $pool.ManagedRuntimeVersion
}

You can go to the bin folder of the site to iterate all dlls and identify the .NET framework version of those dlls. 您可以转到站点的bin文件夹,以迭代所有dll,并标识这些dll的.NET Framework版本。

Function Get-WebsiteDotNetVersion { 
    [CmdletBinding()] 
    Param 
    ( 
        [Parameter(Mandatory=$false)][String]$SiteName 
    ) 

    # get site root directory 
    $site = Get-WebSite -Name $SiteName 
    $binLocation = "$($site.physicalPath)\bin" 

    # get all dlls in bin folder 
    $dllFolder = Get-Item -Path $binLocation 
    $dlls = $dllFolder.GetFiles("*.dll") 

    # analyze dll .net version 
    $set = New-Object System.Collections.Generic.HashSet[String] 
    $dlls | ForEach-Object { 
        $set.Add([Reflection.Assembly]::ReflectionOnlyLoadFrom("$binLocation\$($_.Name)").ImageRuntimeVersion) | Out-Null 
    } 

    # print all dll .NET version 
    $set 
} 

For details please refer to How to get .NET framework version of site running in IIS by PowerShell 有关详细信息,请参阅如何通过PowerShell获取在IIS中运行的网站的.NET Framework版本。

An asp.net application looks at target framework attribute to find out which version of .Net to use 一个asp.net应用程序查看目标框架属性以找出要使用的.Net版本

<httpRuntime targetFramework="4.5" />

For more details refer this msdn .If it does not have that attribute set,It will use runtime 4.0 有关更多详细信息,请参考此msdn 。如果未设置该属性,它将使用运行时4.0

So to correctly figure out the site version, you need 因此,要正确找出站点版本,您需要

  • Get the Application pool runtime version. 获取应用程序池运行时版本。
  • Go to the web.config file and check if targetFramework is present. 转到web.config文件,并检查targetFramework是否存在。
    • If targetFramework is present ,take that 如果存在targetFramework,请采用
    • If not,use the Application pool . 如果不是,请使用应用程序池。 Runtime 运行

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM