Get Dll VersionInfo Using PowerShell

Hello!

let’s not mince words: PowerShell is great. It’s ability to leverage .NET as well as it’s use of modules makes it Object Oriented. And so recently I needed to get the VersionInfo of a given DLL, and so was able to write up a module that did exactly that.

[code language=”powershell”]

function Get-DllVersionInfo
{
param
(
[Parameter(Position=0,mandatory=$true)]
[string] $Dll
)
if(!(Test-Path $Dll -PathType leaf))
{
Write-Error -message “The path to $Dll is either not accessible or does not exist”
return
}
$fileType = [IO.Path]::GetExtension($Dll)
if ($fileType -ne ‘.dll’)
{
Write-Error -Message “The file type at end of $Dll is not a dll.”
return
}
$VersionInfo = (Get-Item $Dll).VersionInfo
$FileVersion = (“{0}.{1}.{2}.{3}” -f $VersionInfo.FileMajorPart,
$VersionInfo.FileMinorPart,
$VersionInfo.FileBuildPart,
$VersionInfo.FilePrivatePart)
return $FileVersion
}

[/code]

Inheriting this value then allows you to do as you wish!

getdllversioninfo

Leave a Reply

Your email address will not be published. Required fields are marked *