Monday, February 2, 2009

PowerShell: GetFileVersion Information as Build Verification Test

As a Dev or QA, we often are worried about the FileVersion information being present on the binaries that we develop and that are shipped to customers. Here’s a small PowerShell script that would help in finding whether we have the fileversion data on all the binaries or not (Currently it checks for .exe and .dll files). Those who know a bit of programming would definitely be able to customize the script as per their requirement.

Please run this carefully. I’m not responsible for any inadvertent consequences.

$files = get-childitem $args -recurse -include *.dll,*.exe
if($files -eq $null)
{
Write-Host "No Exe or dll files present in the folder";
}
else
{
foreach ($i in $files)
{
$ver = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($i).FileVersion
if($ver -eq $null)
{
$i.FullName Out-File NoVersion.txt -append
}
else
{
"{0}`t{1}"-f $i.FullName, [System.Diagnostics.FileVersionInfo]::GetVersionInfo($i).FileVersion out-file Version.xls -append
}
}
}

Run as:
If the above code is copied in a file named: Build-FileVersion-Info.ps1
.\ Build-FileVersion-Info.ps1 FolderName FolderName - is the build folder

Output:
1. We have a file called Version.xls as output that would give the filepaths and fileversion of all the binaries that have fileversion information.
2. Output is also a Noversion.txt file that would give the filepaths of the files that have no fileversion.
3. Output can also be No Exe or dll files present in the folder, which should be self explanatory.

Hope this was useful!!

No comments: