-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get-SqlDscPreferredModule
: Should be possible to specify which version of the SqlServer module is imported
#1965
Comments
Maybe something like
|
It should be possible as per the docs on Import-DSCResource Can you add some more environment details, like is this in Azure, are you using Machine Configuration at all etc etc so that can ensure to give the right advice here. |
Certainly!
What part of the documentation of Import-DSCResource are you referring to? Tracing the code from SqlScriptQuery.psm1 -> InvokeSqlScript -> Import-SqlDscPreferredModule is where SqlServer module is imported. |
You cannot specify what version of SqlServer to import during compilation, or prior to compilation. As mentioned above the (latest installed) module SqlServer is returned by So I think Happy to review a PR that resolves this. |
Get-SqlDscPreferredModule
: Should be possible to specify which version of the SqlServer module is imported
Awesome, thanks for the help! I’ll see if I can cook up a PR here |
While working on this, I found a bug in these lines of code. The version field isn't getting populated for SQLServer module as expected. Only SQLPS. I can't tell exactly why. When I'm debugging, the code seems to exit prematurely on line 116 even though all the keys are present. No error codes. My code changes are modifying this block of code anyway, just thought I'd bring it up. Here is an output when I run this code on my machine:
I tried both PS 7.3.6 and 5.1.19041.3031. As a quick test for someone else to try, this can simply be copy and pasted into any powershell window. Same code, just with the $Name variable populated:
|
It is Here is the working code: $Name = @('sqlserver', 'SQLPS')
$availableModule = Get-Module -FullyQualifiedName $Name -ListAvailable |
Select-Object -Property @(
'Name',
'Path',
@{
Name = 'Version'
Expression = {
if ($_.Name -eq 'SQLPS')
{
<#
Parse the build version number '120', '130' from the Path.
Older version of SQLPS did not have correct versioning.
#>
(Select-String -InputObject $_.Path -Pattern '\\([0-9]{3})\\' -List).Matches.Groups[1].Value
}
else
{
$versionToReturn = $_.Version.ToString()
if ($null -ne $_.PrivateData -and $null -ne $_.PrivateData.PSData -and $null -ne $_.PrivateData.PSData.Prerelease)
{
if (-not [System.String]::IsNullOrEmpty($_.PrivateData.PSData.Prerelease))
{
$versionToReturn = '{0}-{1}' -f $versionToReturn, $_.PrivateData.PSData.Prerelease
}
}
$versionToReturn
}
}
}
)
$availableModule This correctly returns
|
I can incorporate them. Thanks! |
|
…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.
Hello!
We have been using SqlServerDSC on systems that have the SqlServer v21.x.x powershell module installed for some time.
We have a requirement now where we need to have both SqlServer v21 and v22 installed on the system.
Is there any way we can specify which version of SqlServer module is imported in SqlServerDSC? We mainly use the
SqlScriptQuery
module and want to stick with using v21 for some time.Great work, love what you guys have built! Thanks!
The text was updated successfully, but these errors were encountered: