test.ps1

Function Get-FileVersion
    {
        <#
        .SYNOPSIS
            Get-FileVersion will return the File Version from an .EXE or .DLL file.
 
        .DESCRIPTION
            Get-FileVersion will return the File Version from an .EXE or .DLL file.
 
        .PARAMETER Files
            An array of files. Will accept either a string with the path to the file(s), or File System Objects.
 
        .INPUTS
            Will accept pipeline input. Either an array of strings or File System Objects.
 
        .OUTPUTS
            Get-FileVersion will output the FullName of the files and their associated versions, if any.
 
        .EXAMPLE
            PS E:\Scripts\PowerShell> Get-Item C:\Temp\*.dll | Get-FileVersion
 
            File Version
            ---- -------
            C:\Temp\Test1.dll 15.04.859.5
            C:\Temp\Test2.dll 15.04.860.32
 
        .EXAMPLE
            PS E:\Scripts\PowerShell> 'C:\Temp\Test1.dll','C:\Temp\Test2.dll' | Get-FileVersion
 
            File Version
            ---- -------
            C:\Temp\Test1.dll 15.04.859.5
            C:\Temp\Test2.dll 15.04.860.32
        #>

        
        [CmdletBinding()]
        Param([parameter(Mandatory=$True,ValueFromPipeline=$True)] [string[]]$Files)

        Process
            {
                $Objects = @()
                ForEach ( $File in $Files )
                    {
                        $Object = New-Object psobject
                        Try
                            {
                                $File = Get-Item $File -erroraction Stop

                                $Object | Add-Member -Name File -MemberType NoteProperty -Value $File.FullName
                                $Object | Add-Member -Name Version -MemberType NoteProperty -Value $File.versioninfo.fileversion
                            }
                        Catch
                            {
                                $object | Add-Member -Name File -MemberType NoteProperty -Value $File
                                $Object | Add-Member -Name Version -MemberType NoteProperty -Value "File Not Found"
                            }
                        Finally
                            {
                                $Objects += $Object
                            }
                    }
                $Objects
            }
    }

Get-FileVersion Blah