Get-FileVersion
With an endless stream of daily builds, it is essential that a test lab run the latest version.
PS C:\Users\timdunn> dir C:\Windows\System32\*.dll | Get-FileVersion | more
Path Version
---- -------
C:\Windows\System32\aaclient.dll 6.1.7600.16385 (win7_rtm.090713-1255)
C:\Windows\System32\accessibilitycpl.dll 6.1.7600.16385 (win7_rtm.090713-1255)
C:\Windows\System32\ACCTRES.dll 6.1.7600.16385 (win7_rtm.090713-1255)
Mind you, this can all be done with
(Get-ChildItem) | Select-Object @{ n = ‘Path’; e = { $_.FullName; }}, @{ n= ‘Version’; e = { (Get-Item $_.FullName).VersionInfo.FileVersion; }}
but this way has better error handling if the file isn’t found or the version info is not present (such as in scripts and text files).
function Get-FileVersion {
param (
[Parameter(
Position = 0,
Mandatory = $true,
ValueFromPipeline = $true,
ValueFromPipelineByPropertyName = $true
)] [object[]]$path
);
process {
$output = $true | Select-Object -Property Path, Version;
foreach ($myPath in $path) {
if ($myPath.GetType().Name -eq 'FileInfo') { $myPath = $myPath.FullName; }
$output.Path = $myPath;
if (Test-Path $myPath) {
$output.Version = (Get-Item $myPath).VersionInfo.FileVersion;
if (!$output.Version) { $output.Version = 'VersionNotFound'; }
} else {
$output.Version = 'FileNotFound';
}
$output;
}
}
}