Skip to content

Commit

Permalink
Changes to Connect-SQL and Import-SQLPSModule
Browse files Browse the repository at this point in the history
Now it correctly loads the correct assemblies when SqlServer module is present (issue dsccommunity#649).
Now SQLPS module will be correctly loaded (discovered) after installation of SQL Server (issue dsccommunity#659). Previously resources depending on SQLPS module could fail because SQLPS was not found after installation because the PSModulePath environment variable in the (LCM) PowerShell session did not contain the new module path.
  • Loading branch information
johlju committed Jul 8, 2017
1 parent dbbd115 commit 2b667db
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@
parameter Verbose.
- Moved localization strings from xSQLServer.strings.psd1 to
xSQLServerHelper.strings.psd1.
- Changes to Connect-SQL and Import-SQLPSModule
- Now it correctly loads the correct assemblies when SqlServer module is
present (issue #649).
- Now SQLPS module will be correctly loaded (discovered) after installation
of SQL Server. Previously resources depending on SQLPS module could fail
because SQLPS was not found after installation because the PSModulePath
environment variable in the (LCM) PowerShell session did not contain the new
module path.
- Changes to xSQLServerSetup
- BREAKING CHANGE: Replaced StartWin32Process helper function with the cmdlet
Start-Process (issue #41, #93 and #126).
Expand Down
1 change: 1 addition & 0 deletions Tests/Unit/xSQLServerHelper.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ InModuleScope $script:moduleName {
Describe 'Testing Connect-SQL' -Tag ConnectSql {
BeforeEach {
Mock -CommandName New-InvalidOperationException -MockWith $mockThrowLocalizedMessage -Verifiable
Mock -CommandName Import-SQLPSModule
Mock -CommandName New-Object `
-MockWith $mockNewObject_MicrosoftDatabaseEngine `
-ParameterFilter $mockNewObject_MicrosoftDatabaseEngine_ParameterFilter `
Expand Down
11 changes: 10 additions & 1 deletion xSQLServerHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function Connect-SQL
$SetupCredential
)

$null = [System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.Smo')
Import-SQLPSModule

if ($SQLInstanceName -eq 'MSSQLSERVER')
{
Expand Down Expand Up @@ -697,6 +697,15 @@ function Import-SQLPSModule
else
{
Write-Verbose -Message ($script:localizedData.PreferredModuleNotFound) -Verbose

<#
After installing SQL Server the current PowerShell session doesn't know about the new path
that was added for the SQLPS module.
This reloads PowerShell session environment variable PSModulePath to make sure it contains
all paths.
#>
$env:PSModulePath = [System.Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')

$module = (Get-Module -FullyQualifiedName 'SQLPS' -ListAvailable).Name
}

Expand Down

0 comments on commit 2b667db

Please sign in to comment.