-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get-SqlDscPreferredModule: Optionally specify which version of the SQ…
…L module is imported (#1966) - SqlServerDsc - `Get-SqlDscPreferredModule` - Optionally specify what version of the the SQL preferred module to be imported using the SMODefaultModuleVersion environment variable ([issue #1965](#1965)). - `Get-SqlDscPreferredModule` - Now returns a PSModuleInfo object instead of just the module name. - `Import-SqlDscPreferredModule` - Handles PSModuleInfo objects from `Get-SqlDscPreferredModule` instead of strings. - Sets -ErrorAction 'Stop' on Get-SqlDscPreferredModule to throw an error if no SQL module is found. The script-terminating error is caught and made into a statement-terminating error. - Removed PreferredModule_ModuleFound string in favor for more verbose PreferredModule_ModuleVersionFound. - New private command: - Get-SMOModuleCalculatedVersion - Returns the version of the SMO module as a string. SQLPS version 120 and 130 do not have the correct version set, so the file path is used to calculate the version.
- Loading branch information
Showing
8 changed files
with
641 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<# | ||
.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. | ||
.OUTPUTS | ||
[System.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 = (Select-String -InputObject $PSModuleInfo.Path -Pattern '\\([0-9]{3})\\' -List).Matches.Groups[1].Value | ||
} | ||
else | ||
{ | ||
$version = $PSModuleInfo.Version.ToString() | ||
|
||
if ($PSModuleInfo.PrivateData.PSData.Prerelease) | ||
{ | ||
$version = '{0}-{1}' -f $PSModuleInfo.Version, $PSModuleInfo.PrivateData.PSData.Prerelease | ||
} | ||
} | ||
|
||
return $version | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.