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).
  • Loading branch information
johlju committed Jun 23, 2017
1 parent d5c3276 commit 307fddb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
- Test-SQLDscParameterState helper function can now correctly pass a CimInstance as DesiredValue.
- Test-SQLDscParameterState helper function will now output a warning message
if the value type of a desired value is not supported.
- Changes to Connect-SQL and Import-SQLPSModule
- Now it correctly loads the correct assemblies when SqlServer module is present (issue #649).
- Changes to xSQLServerSetup
- BREAKING CHANGE: Replaced StartWin32Process helper function with the cmdlet Start-Process (issue #41, #93 and #126).
- BREAKING CHANGE: The parameter SetupCredential has been removed since it is no longer needed. This is because the resource now support the built-in PsDscRunAsCredential.
Expand Down
11 changes: 10 additions & 1 deletion xSQLServerHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Connect-SQL
$SetupCredential
)

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

if ($SQLInstanceName -eq "MSSQLSERVER")
{
Expand Down Expand Up @@ -674,6 +674,15 @@ function Import-SQLPSModule
else
{
New-VerboseMessage -Message 'Module SqlServer not found, trying to use older SQLPS module.'

<#
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 307fddb

Please sign in to comment.