Closed gillg closed 1 year ago
I just found a slight difference between a working server and a failing server:
Working:
[[SqlScript]DirectResourceAccess] Importing PowerShell module 'SqlServer' with version '21.1.18256' from path 'C:\Program Files\WindowsPowerShell\Modules\SqlServer\21.1.18256\SqlServer.psm1'. (SQLCOMMON0025)
Failing:
[[SqlScript]DirectResourceAccess] Importing PowerShell module 'SqlServer' with version '22.0.59' from path 'C:\Program Files\WindowsPowerShell\Modules\SqlServer\22.0.59\SqlServer.psm1'. (SQLCOMMON0025)
I made the test... It's the root cause !
The new version 22.0.59 was just published yesterday... I'm very unlucky but that means SqlServerDsc
will probably have many unexpected issues very soon !
You should ask for Get-InstalledModule -Name SqlServer
in your issue template now 😅
You should ask for Get-InstalledModule -Name SqlServer in your issue template now
We do. In the template for "Problem with resource". 🙂
Get-Module -Name '*sql*' -ListAvailable | ? Name -ne 'SqlServerDsc' | ft Name,Version,Path
I saw that the new version of SqlServer was released so it might break stuff. It works with the preview version (22.0.49-preview), but apparently there are more breaking changes in this new release.
The PowerShell function
Invoke-SqlScript
should defaults to$null
for the argument$Variable
.
It should only pass in the parameter Variable if it is passed to the function. So it would need to be removed if it is not passed.
if (-not $PSBoundParameters.ContainsKey('Variable'))
{
$PSBoundParameters.Remove('Variable')
}
But instead of continue on with this "reverse-logic" it could be simplified to add parameters to a new hashtable that is passed to Invoke-SqlCmd
, the new hastable will then contain the parameter if it is part of $PSBoundParameters
.
I can review a PR that fixes this if someone sends one in.
Problem description
Probably due to a change in a background lib (ps version or something else ?) a previous command which was working is not working anymore. But that highlights an inconsistency in the script SqlScript parameters validation.
The
Variable
is optional but the script fails now if we don't define it.Verbose logs
How to reproduce
Nevermind the content of the sql files below the script below is now faling with logs above.
EDIT: You must use the version 22 of the module SqlServer
Install-Module SqlServer -RequiredVersion 22.0.59 -Force
Expected behavior
The script should pass with or without Variable defined.
Current behavior
By adding
Variable=@("test=test")
in script parameters that works.Refering to
(Get-CimClass -ClassName DSC_SqlScript -Namespace root\Microsoft\Windows\DesiredStateConfiguration).CimClassProperties | fl
The "Variable" option can be nullBut the validation made by the powershell engine here is failing https://github.com/dsccommunity/SqlServerDsc/blob/4602416a69867c24c9788dd9afd99b27982ecacd/source/Modules/SqlServerDsc.Common/SqlServerDsc.Common.psm1#L2090
Suggested solution
The powershell function
Invoke-SqlScript
should defaults to$null
for the argument$Variable
Does anyone has an idea why it is working on another server with the exact same module version, sql files, psversiontable, windows build version ?
Operating system the target node is running
PowerShell version and build the target node is running
Module version used