Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get-SqlDscPreferredModuleName: New command proposal #1879

Closed
johlju opened this issue Mar 25, 2023 · 0 comments · Fixed by #1898
Closed

Get-SqlDscPreferredModuleName: New command proposal #1879

johlju opened this issue Mar 25, 2023 · 0 comments · Fixed by #1898
Labels
command proposal The issue is proposing to add a new command to the module.

Comments

@johlju
Copy link
Member

johlju commented Mar 25, 2023

Command proposal

Suggest adding a new command Get-SqlDscPreferredModuleName that will return the name (or path) of the best available module name to import.

Proposed parameters

Parameter Mandatory Data type Description Default value Allowed values
PreferredModule No String[] Specifies the name of one or more preferred modules. The ordered specified will be the order they will be evaluated, Defaults to 'SqlServer'. @('SqlServer') Any string

Special considerations or limitations

The following code should be moved, and instead replaced with this new command:

$availableModuleName = $null
# Get the newest SqlServer module if more than one exist
$availableModule = Get-Module -FullyQualifiedName $PreferredModule -ListAvailable |
Sort-Object -Property 'Version' -Descending |
Select-Object -First 1 -Property 'Name', 'Path', 'Version'
if ($availableModule)
{
$availableModuleName = $availableModule.Name
Write-Verbose -Message ($script:localizedData.PreferredModule_ModuleFound -f $availableModuleName)
}
else
{
Write-Verbose -Message ($script:localizedData.PreferredModule_ModuleNotFound)
# Only run on Windows that has Machine state.
if (-not ($IsLinux -or $IsMacOS))
{
<#
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.
#>
Set-PSModulePath -Path ([System.Environment]::GetEnvironmentVariable('PSModulePath', 'Machine'))
}
# Get the newest SQLPS module if more than one exist.
$availableModule = Get-Module -FullyQualifiedName 'SQLPS' -ListAvailable |
Select-Object -Property Name, Path, @{
Name = 'Version'
Expression = {
# Parse the build version number '120', '130' from the Path.
(Select-String -InputObject $_.Path -Pattern '\\([0-9]{3})\\' -List).Matches.Groups[1].Value
}
} |
Sort-Object -Property 'Version' -Descending |
Select-Object -First 1
if ($availableModule)
{
# This sets $availableModuleName to the Path of the module to be loaded.
$availableModuleName = Split-Path -Path $availableModule.Path -Parent
}
}

@johlju johlju changed the title Get-SqlDscPreferredModuleName: New command proposal Get-SqlDscPreferredModuleName: New command proposal Mar 25, 2023
@johlju johlju added help wanted The issue is up for grabs for anyone in the community. command proposal The issue is proposing to add a new command to the module. labels Mar 25, 2023
@johlju johlju added in progress The issue is being actively worked on by someone. and removed help wanted The issue is up for grabs for anyone in the community. labels Apr 2, 2023
johlju added a commit that referenced this issue Apr 8, 2023
- SqlServerDsc
  - New public command:
    - `Get-SqlDscPreferredModule` - Returns the name of the first available
      preferred module (issue #1879).
- `Import-SqlDscPreferredModule`
  - Refactor to re-use the command `Get-SqlDscPreferredModule`.
@johlju johlju removed the in progress The issue is being actively worked on by someone. label Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
command proposal The issue is proposing to add a new command to the module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant