functions/Get-PSModulePath.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
function Get-PSModulePath { [CmdletBinding()] [OutputType('string')] Param( [Parameter()] [ValidateSet('All', 'User', 'Global')] [string] $Scope = 'All' ) # Determine platforms if (Test-IsWindows -eq $true) { # Windows $script:UserPSModulePath = Join-Path ([Environment]::GetFolderPath("MyDocuments")) 'WindowsPowerShell/Modules' $script:GlobalPSModulePath = Join-Path $env:ProgramFiles 'WindowsPowerShell/Modules' } else { # Others (MacOS or Linux) $script:UserPSModulePath = Join-Path $env:HOME '/.local/share/powershell/Modules' $script:GlobalPSModulePath = '/usr/local/share/powershell/Modules' } # Output switch ($Scope) { 'All' { $env:PSModulePath break } 'User' { $script:UserPSModulePath break } 'Global' { $script:GlobalPSModulePath break } } } |