Skip to content

Commit

Permalink
SqlServerDsc: Improvement to how Import-SQLPSModule import module (#1175
Browse files Browse the repository at this point in the history
)

- Changes to SqlServerDsc
  - Updated helper function `Import-SQLPSModule`
    - To only import module if the
      module does not exist in the session.
    - To always import the latest version of 'SqlServer' or 'SQLPS' module, if
      more than one version exist on the target node. It will still prefer to
      use 'SqlServer' module.
  - Changes to SqlAG
    - Removed excess `Import-SQLPSModule` call.
  - Changes to SqlSetup
    - Now after a successful install the "SQL PowerShell module" is reevaluated and
      forced to be reimported into the session. This is to support that a never
      version of SQL Server was installed side-by-side so that SQLPS module should
      be used instead.
  • Loading branch information
johlju authored Jul 7, 2018
1 parent 4997ae4 commit ac284e9
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 92 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
- Updated helper function Restart-SqlService to have to new optional parameters
`SkipClusterCheck` and `SkipWaitForOnline`. This was to support more aspects
of the resource SqlServerNetwork.
- Updated helper function `Import-SQLPSModule`
- To only import module if the
module does not exist in the session.
- To always import the latest version of 'SqlServer' or 'SQLPS' module, if
more than one version exist on the target node. It will still prefer to
use 'SqlServer' module.
- Changes to SqlAlwaysOnService
- Integration tests was updated to handle new IPv6 addresses on the AppVeyor
build worker ([issue #1155](https://github.com/PowerShell/SqlServerDsc/issues/1155)).
Expand All @@ -15,6 +21,13 @@
enabling and disabling the protocol.
- Added integration tests for this resource
([issue #751](https://github.com/PowerShell/SqlServerDsc/issues/751)).
- Changes to SqlAG
- Removed excess `Import-SQLPSModule` call.
- Changes to SqlSetup
- Now after a successful install the "SQL PowerShell module" is reevaluated and
forced to be reimported into the session. This is to support that a never
version of SQL Server was installed side-by-side so that SQLPS module should
be used instead.

## 11.3.0.0

Expand Down
2 changes: 0 additions & 2 deletions DSCResources/MSFT_SqlAG/MSFT_SqlAG.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ function Set-TargetResource
$ProcessOnlyOnActiveNode
)

Import-SQLPSModule

# Connect to the instance
$serverObject = Connect-SQL -SQLServer $ServerName -SQLInstanceName $InstanceName

Expand Down
25 changes: 24 additions & 1 deletion DSCResources/MSFT_SqlSetup/MSFT_SqlSetup.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1420,8 +1420,9 @@ function Set-TargetResource
elseif ($processExitCode -ne 0)
{
$setupExitMessageError = ('{0} {1}' -f $setupExitMessage, ($script:localizedData.SetupFailed))

Write-Warning $setupExitMessageError

$setupEndedInError = $true
}
else
{
Expand All @@ -1436,13 +1437,35 @@ function Set-TargetResource
{
Write-Verbose -Message $script:localizedData.Reboot

# Rebooting, so no point in refreshing the session.
$forceReloadPowerShellModule = $false

$global:DSCMachineStatus = 1
}
else
{
Write-Verbose -Message $script:localizedData.SuppressReboot
$forceReloadPowerShellModule = $true
}
}
else
{
$forceReloadPowerShellModule = $true
}

if ((-not $setupEndedInError) -and $forceReloadPowerShellModule)
{
<#
Force reload of SQLPS module in case a newer version of
SQL Server was installed that contains a newer version
of the SQLPS module, although if SqlServer module exist
on the target node, that will be used regardless.
This is to make sure we use the latest SQLPS module that
matches the latest assemblies in GAC, mitigating for example
issue #1151.
#>
Import-SQLPSModule -Force
}

if (-not (Test-TargetResource @PSBoundParameters))
{
Expand Down
Loading

0 comments on commit ac284e9

Please sign in to comment.