Get-FileVersion.psm1

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)] $Files) #[string[]]

        Process
            {
                $Objects = @()
                ForEach ( $File in $Files )
                    {
                        $Object = New-Object psobject
                        Try
                            {
                                If ( $file -is [String] )
                                    {
                                        $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
            }
    }


Function Get-LastWriteTime
    {
        <#
        .SYNOPSIS
            Get-LastWriteTime will return the Last Write Time from a file.
 
        .DESCRIPTION
            Get-LastWriteTime will return the Last Write Time from a 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-LastWriteTime will output the FullName of the files and their associated Last Write Time.
 
        .EXAMPLE
            PS E:\Scripts\PowerShell> Get-Item C:\Temp\*.dll | Get-LastWriteTime
 
            File LastWriteTime
            ---- -------------
            C:\Temp\Test1.dll 8/7/2015 3:53:38 PM
            C:\Temp\Test2.dll 8/7/2015 3:10:28 PM
 
        .EXAMPLE
            PS E:\Scripts\PowerShell> 'C:\Temp\Test1.dll','C:\Temp\Test2.dll' | Get-LastWriteTime
 
            File LastWriteTime
            ---- -------------
            C:\Temp\Test1.dll 8/7/2015 3:53:38 PM
            C:\Temp\Test2.dll 8/7/2015 3:10:28 PM
        #>

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

        Process
            {
                $Objects = @()
                ForEach ( $File in $Files )
                    {
                        $Object = New-Object psobject
                        $File = get-item $File
                        $Object | Add-Member -Name File -MemberType NoteProperty -Value $File.FullName

                        Try
                            {
                                $File = Get-Item $File -ErrorAction Stop
                                
                                If ( $UTC )
                                    {
                                        $Object | Add-Member -Name LastWriteTime -MemberType NoteProperty -Value $File.LastWriteTimeUTC
                                    }
                                Else
                                    {
                                        $Object | Add-Member -Name LastWriteTime -MemberType NoteProperty -Value $File.LastWriteTime
                                    }
                            }
                        Catch
                            {
                                $Object | Add-Member -Name LastWriteTime -MemberType NoteProperty -Value "File Not Found"
                            }
                        Finally
                            {
                                $Objects += $Object
                            }
                    }
                $Objects
            }
    }




New-Alias glwt Get-LastWriteTime
New-Alias gfv Get-FileVersion

Export-ModuleMember -Function Get-LastWriteTime, Get-FileVersion -Alias glwt, gfv