[英]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
}
一個asp.net應用程序查看目標框架屬性以找出要使用的.Net版本
<httpRuntime targetFramework="4.5" />
有關更多詳細信息,請參考此msdn 。如果未設置該屬性,它將使用運行時4.0
因此,要正確找出站點版本,您需要
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.