File Version in Window 7 using PowerShell

Recently I have to list down the Name and File Version of few MFC dlls. So the straight forward way was to:-
Select the dll, Right Mouse, the go to the Details Tab and list down the File Version as shown below.






So this manual method is ok if we have one or two dlls, but if we have many files then we need some automated method.
PowerShell provides few methods for doing this.
Start the PowerShell by pressing the Windows keys and then typing PowerShell in “Search Program and Files” search area. for e.g.






Now click “Windows PowerShell” to run the PowerShell
Use the “cd” command to go in the directory where our dlls are located.
e.g. cd C:\Test
The type “dir” command to see the content of the folder




Now there are few options to get the Version Info.

Option1:-

Use the following command:-
Get-ChildItem *.dll | %{ $_.VersionInfo }






Option2:-

Use the command:-

Get-ChildItem *.dll| Select-Object -ExpandProperty VersionInfo | Select-Object -Property ProductVersion,FileVersion,Filename






Option 3:-

Use the command:-
Get-ChildItem *.dll | Format-Table Name, @{ Label = 'FileVersion'; Expression = { $_.VersionInfo.FileVersion }},@{ Label = 'ProductVersion'; Expression = { $_.VersionInfo.ProductVersion }}








With this option we can also use an option Autosize to print the output in a more formatted way for e.g. just add –Autosize at the end of the above command:-








Note that in all the 3 option *.dll is used, that just a wildcard to list the version only for the dll, This can be applied to other files also like .exe.

If we want to redirect the output to a file, then “Out-File” command can be used
For e.g.
Just pipe the last commad to Out-File path_where_to_store_the_output\file_name.txt

Get-ChildItem *.dll | Format-Table Name, @{ Label = 'FileVersion'; Expression = { $_.VersionInfo.FileVersion }},@{ Label = 'ProductVersion'; Expression = { $_.VersionInfo.ProductVersion }}| Out-File C:\Test\File_Version.txt

A new text file named File_Version.txt will be created in the C:\Test Directory.

The content of that file can be viewed with “cat” command







Comments

Popular Posts