Closed RDiegoli01 closed 1 year ago
Thanks for reporting this. Guess we need to add integration tests that runs with SQLPS as well. 🙂
Added -ListAvailable parameter to Get-Module and it worked
On what line did you add that to?
Hey @johlju what I meant in my suggestion is that I added in a very simple test simply trying to call
Get-Module -Name "C:\Program Files (x86)\Microsoft SQL Server\160\Tools\PowerShell\Modules\SQLPS"
which gives the same error in the logs.Get-Module -ListAvailable -Name "C:\Program Files (x86)\Microsoft SQL Server\160\Tools\PowerShell\Modules\SQLPS"
yields me the desired module.I couldn't get the time to discover exactly where in SqlScriptQuery
is the failing Get-Module
call.
Ah, cool. I will figure it out. It was most likely one of the changed lines to support dbatools as a preferred module. I did not know Get-Module
worked that way. I will get this fixed as soon as possible. This weekend if not quicker.
It this line that fails.
It should check for Get-Module -Name 'SQLPS'
, so when it get the path it should just use the leaf part of the path.
So the line should be
$loadedModuleName = (Get-Module -Name (Split-Path -Path $availableModuleName -Leaf) | Select-Object -First 1).Name
@RDiegoli01 could you possible confirm this by changing that line in the file SqlServerDsc.psm1 on a node that fails? The line is part of the command Import-SqlDscPreferredModule
.
@johlju tested your suggestion on a stack I had. It worked perfectly fine!
Great. I sent in a PR with the change. Will merge and release as soon as the tests pass.
Problem description
When calling the attached DSC configuration, we see an error related to our
SqlScriptQuery
call.It looks like the target VM is trying to import the
SQLPS
module (from SQL Server 2022), but the Get-Module is passing bad parameters (see verbose logs).We caught this last week we were using
SqlServerDsc
16.2 which was working fine. Then our script updated it to 16.3 (released last week) and we started seeing this error.Verbose logs
DSC configuration
Suggested solution
Tested following exactly what the error message suggested:
-ListAvailable
parameter toGet-Module
and it worked-Name
(i.e.Get-Module -Name SQLPS
)SQL Server edition and version
SQL Server PowerShell modules
Operating system
PowerShell version
SqlServerDsc version