dsccommunity / DscResource.Common

This module contains common functions that are used in DSC resources.
https://dsccommunity.org
MIT License
9 stars 9 forks source link

`Get-PSModulePath`: New command proposal #103

Closed johlju closed 1 year ago

johlju commented 1 year ago

Suggest adding a new command with a mandatory parameter FromTarget with the type String[] that has a validate set of Session, User, Machine. The command returns the concatenated paths (separated with semi-colon) depending on what targets was passed to the parameter. Multiple targets should be able to be passed.

This command should be used by Set-PSModulePath as suggested in issue #102.

The code suggestion:

            <#
                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 ';'