Skip to content

Commit

Permalink
Get-SqlDscPreferredModule: Using command Get-PSModulePath (#1905)
Browse files Browse the repository at this point in the history
- `Get-SqlDscPreferredModule`
  - Re-using the command `Get-PSModulePath` from the module DscResource.Common.
  • Loading branch information
johlju authored Apr 10, 2023
1 parent 501bfe1 commit b12e5bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- New public command:
- `Get-SqlDscPreferredModule` - Returns the name of the first available
preferred module ([issue #1879](https://github.com/dsccommunity/SqlServerDsc/issues/1879)).
- Re-using the command `Get-PSModulePath` from the module DscResource.Common.
- SqlSecureConnection
- Added new parameter `ServerName` that will be used as the host name when
restarting the SQL Server instance. The specified value should be the same
Expand Down
23 changes: 1 addition & 22 deletions source/Public/Get-SqlDscPreferredModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,7 @@ function Get-SqlDscPreferredModule
contains all paths.
#>

<#
TODO: This should be replaced by Get-PSModulePath that is in
PR https://github.com/dsccommunity/DscResource.Common/pull/104.
#>

<#
Get the environment variables from all targets session, user and machine.
Casts the value to System.String to convert $null values to empty string.
#>
$modulePathSession = [System.String] [System.Environment]::GetEnvironmentVariable('PSModulePath')
$modulePathUser = [System.String] [System.Environment]::GetEnvironmentVariable('PSModulePath', 'User')
$modulePathMachine = [System.String] [System.Environment]::GetEnvironmentVariable('PSModulePath', 'Machine')

$modulePath = $modulePathSession, $modulePathUser, $modulePathMachine -join ';'

$modulePathArray = $modulePath -split ';' |
Where-Object -FilterScript {
-not [System.String]::IsNullOrEmpty($_)
} |
Sort-Object -Unique

$modulePath = $modulePathArray -join ';'
$modulePath = Get-PSModulePath -FromTarget 'Session', 'User', 'Machine'

Set-PSModulePath -Path $modulePath
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Unit/Public/Get-SqlDscPreferredModule.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ Describe 'Get-SqlDscPreferredModule' -Tag 'Public' {
Context 'When specifying the parameter Refresh' {
BeforeAll {
Mock -CommandName Set-PSModulePath
Mock -CommandName Get-PSModulePath -MockWith {
return 'MockPath'
}

Mock -CommandName Get-Module -MockWith {
return @{
Name = 'SqlServer'
Expand Down

0 comments on commit b12e5bb

Please sign in to comment.