-
Notifications
You must be signed in to change notification settings - Fork 29
/
Get-AssemblyFramework.ps1
38 lines (31 loc) · 1.12 KB
/
Get-AssemblyFramework.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<#
.SYNOPSIS
Gets the framework version an assembly was compiled for.
.INPUTS
Objects with System.String properties named Path or FullName.
.OUTPUTS
System.Management.Automation.PSCustomObject with RuntimeVersion and CompileVersion properties.
.FUNCTIONALITY
DotNet
.LINK
https://stackoverflow.com/questions/3460982/determine-net-framework-version-for-dll#25649840
.EXAMPLE
Get-AssemblyFramework.ps1 Program.exe
RuntimeVersion CompileVersion
-------------- --------------
v4.0.30319 .NETFramework,Version=v4.7.2
#>
[CmdletBinding()][OutputType([Management.Automation.PSCustomObject])] Param(
# The assembly to get the framework version of.
[Parameter(Position=0,Mandatory=$true,ValueFromPipelineByPropertyName=$true)][Alias('FullName')][string] $Path
)
Process
{
$assembly = [Reflection.Assembly]::ReflectionOnlyLoadFrom((Resolve-Path $Path))
[PSCustomObject]@{
RuntimeVersion = $assembly.ImageRuntimeVersion
CompileVersion = $assembly.CustomAttributes |
Where-Object {$_.AttributeType.Name -eq "TargetFrameworkAttribute" } |
ForEach-Object {$_.ConstructorArguments.value}
}
}