dsccommunity / SqlServerDsc

This module contains DSC resources for deployment and configuration of Microsoft SQL Server.
MIT License
360 stars 225 forks source link

SqlAlwaysOnService: Loading wrong SQLPS when both SQL Server 2014 and SQL Server 2016 exists #806

Open johlju opened 7 years ago

johlju commented 7 years ago

Details of the scenario you tried and the problem that is occurring: Enable AlwaysOn fails to configure SQL Server 2016 when both SQL Server 2014 and SQL Server 2016 is installed and having SQLPS module installed for both major version. The reason is that sometimes the wrong SQLPS module is loaded (because it is the first in the $env:PATH list).

Could not obtain information about SQL Server Service 'MSSQL$DSCSQL2016'.
    + CategoryInfo          : ResourceUnavailable: (MSSQL$DSCSQL2016:) [], CimException
    + FullyQualifiedErrorId : ServiceError,Microsoft.SqlServer.Management.PowerShell.Hadr.EnableSqlHADRServiceCommand
    + PSComputerName        : localhost

The DSC configuration that is using the resource (as detailed as possible):

xSQLServerAlwaysOnService 'Integration_Test'
{
     Ensure               = 'Present'
     SQLServer            = $Node.ComputerName
     SQLInstanceName      = $Node.InstanceName
     RestartTimeout       = $Node.RestartTimeout
     PsDscRunAsCredential = $SqlInstallCredential
}

Version of the Operating System, SQL Server and PowerShell the DSC Target Node is running: Windows Server 2016, SQL Server 2014 and 2016, WMF 5.1

What module (SqlServer or SQLPS) and which version of the module the DSC Target Node is running: SQLPS

Version of the DSC module you're using, or 'dev' if you're using current dev branch: Dev

johlju commented 7 years ago

One workaround is to use the SqlServer PowerShell module.

johlju commented 7 years ago

The integration tests might need a workaround for this as well. I added this code to the integration tests I am working on. But I revert back to make sure only on SQLPS module is available for the time being.

<#
    This must be done before SQLPS modules are restored. Otherwise
    this could complain that the same cmdlets already exist.
    This is also a workaround for having multiple SQLPS modules installed
    on the AppVeyor build worker (see issue #806).
#>
Write-Verbose -Message 'Installing SqlServer PowerShell module.' -Verbose
Install-Module -Name SqlServer -Force