forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-FileVersionInformation.ps1
More file actions
66 lines (50 loc) · 1.69 KB
/
Get-FileVersionInformation.ps1
File metadata and controls
66 lines (50 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<#
.SYNOPSIS
Returns the version information for a file.
.DESCRIPTION
Returns the version information for a file.
.PARAMETER FilePath
Specifies the file for which to return the version information.
.EXAMPLE
Get-FileVersionInformation -FilePath 'E:\setup.exe'
Returns the version information for the file setup.exe.
.EXAMPLE
Get-FileVersionInformation -FilePath (Get-Item -Path 'E:\setup.exe')
Returns the version information for the file setup.exe.
.INPUTS
`System.IO.FileInfo`
Accepts a file path via the pipeline.
.OUTPUTS
`System.Diagnostics.FileVersionInfo`
Returns the file version information.
#>
function Get-FileVersionInformation
{
[OutputType([System.Diagnostics.FileVersionInfo])]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[System.IO.FileInfo]
$FilePath
)
process
{
$originalErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Stop'
$file = Get-Item -Path $FilePath -ErrorAction 'Stop'
$ErrorActionPreference = $originalErrorActionPreference
if ($file.PSIsContainer)
{
$PSCmdlet.ThrowTerminatingError(
[System.Management.Automation.ErrorRecord]::new(
$script:localizedData.FileVersionInformation_Get_FilePathIsNotFile,
'GFPVI0001', # cSpell: disable-line
[System.Management.Automation.ErrorCategory]::InvalidArgument,
$file.FullName
)
)
}
return $file.VersionInfo
}
}