forked from dsccommunity/SqlServerDsc
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGet-SMOModuleCalculatedVersion.ps1
More file actions
70 lines (56 loc) · 1.95 KB
/
Get-SMOModuleCalculatedVersion.ps1
File metadata and controls
70 lines (56 loc) · 1.95 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
67
68
69
70
<#
.SYNOPSIS
Returns the calculated version of an SMO PowerShell module.
.DESCRIPTION
Returns the calculated version of an SMO PowerShell module.
For SQLServer, the version is calculated using the System.Version
field with '-preview' appended for pre-release versions . For
example: 21.1.1 or 22.0.49-preview
For SQLPS, the version is calculated using the path of the module. For
example:
C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules
returns 130
.PARAMETER PSModuleInfo
Specifies the PSModuleInfo object for which to return the calculated version.
.EXAMPLE
Get-SMOModuleCalculatedVersion -PSModuleInfo (Get-Module -Name 'sqlps')
Returns the calculated version as a string.
.INPUTS
`System.Management.Automation.PSModuleInfo`
Accepts a PowerShell module info object via the pipeline.
.OUTPUTS
`System.String`
Returns the calculated version as a string.
#>
function Get-SMOModuleCalculatedVersion
{
[OutputType([System.String])]
[CmdletBinding()]
param
(
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[System.Management.Automation.PSModuleInfo]
$PSModuleInfo
)
process
{
$version = $null
if ($PSModuleInfo.Name -eq 'SQLPS')
{
<#
Parse the build version number '120', '130' from the Path.
Older version of SQLPS did not have correct versioning.
#>
$version = $PSModuleInfo.Path -replace '.*\\(\d{2})(\d)\\.*', '$1.$2'
}
else
{
$version = $PSModuleInfo.Version.ToString()
if ($PSModuleInfo.PrivateData.PSData.Prerelease)
{
$version = '{0}-{1}' -f $PSModuleInfo.Version, $PSModuleInfo.PrivateData.PSData.Prerelease
}
}
return $version
}
}