繁体   English   中英

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

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

有没有一种方法可以使用PowerShell来获取Web应用程序在IIS中运行的.NET框架?

我已经能够使用以下命令获取网站名称,并看到应用程序池已设置为“ Clr4IntegratedAppPool”,但是我没有找到一种方法来确定网站本身正在运行的.NET版本。

为澄清起见,我正在尝试获取网站本身的.NET版本,而不是应用程序池。 例如,如果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 )
}

这是一种方法

$myServer = "name of server"

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

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

您可以转到站点的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 
} 

有关详细信息,请参阅如何通过PowerShell获取在IIS中运行的网站的.NET Framework版本。

一个asp.net应用程序查看目标框架属性以找出要使用的.Net版本

<httpRuntime targetFramework="4.5" />

有关更多详细信息,请参考此msdn 。如果未设置该属性,它将使用运行时4.0

因此,要正确找出站点版本,您需要

  • 获取应用程序池运行时版本。
  • 转到web.config文件,并检查targetFramework是否存在。
    • 如果存在targetFramework,请采用
    • 如果不是,请使用应用程序池。 运行

希望这可以帮助!

暂无
暂无

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

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