@@ -254,6 +254,7 @@ function Install-ModuleFast {
254
254
begin {
255
255
trap {$PSCmdlet.ThrowTerminatingError ($PSItem )}
256
256
257
+ $CustomPSModulePath = Get-CustomPSModulePath
257
258
# Setup the Destination repository
258
259
$defaultRepoPath = $ (Join-Path ([Environment ]::GetFolderPath(' LocalApplicationData' )) ' powershell/Modules' )
259
260
@@ -269,7 +270,13 @@ function Install-ModuleFast {
269
270
$Destination = ' CurrentUser'
270
271
}
271
272
if (-not $Destination ) {
272
- $Destination = $defaultRepoPath
273
+ $Destination =
274
+ if ($CustomPSModulePath ) {
275
+ $CustomPSModulePath
276
+ }
277
+ else {
278
+ $defaultRepoPath
279
+ }
273
280
} elseif ($IsWindows -and $Destination -eq ' CurrentUser' ) {
274
281
$windowsDefaultDocumentsPath = Join-Path ([Environment ]::GetFolderPath(' MyDocuments' )) ' PowerShell/Modules'
275
282
$Destination = $windowsDefaultDocumentsPath
@@ -2159,6 +2166,38 @@ function Approve-Action {
2159
2166
2160
2167
return $ThisCmdlet.ShouldProcess ($Target , $Action )
2161
2168
}
2169
+ function Get-CustomPSModulePath {
2170
+ <#
2171
+ . DESCRIPTION
2172
+ Gets the custom PSModulePath from the powershell.config.json file in the user's profile directory or $PSHOME.
2173
+ user profile is preferred over global profile.
2174
+ . PARAMETER Config
2175
+ The path to the powershell.config.json file. If not specified, it will default to the user's profile directory.
2176
+ this should only be used in testing scenarios.
2177
+ #>
2178
+ [cmdletbinding ()]
2179
+ param (
2180
+ [String ] $Config
2181
+ )
2182
+ if (-Not $Config ) {
2183
+ $Config = Join-Path (Split-Path $PROFILE.CurrentUserCurrentHost ) ' powershell.config.json'
2184
+ }
2185
+ if (Test-Path - Path $Config - PathType Leaf) {
2186
+ $json = Get-Content - LiteralPath $Config - Raw | ConvertFrom-Json
2187
+ $LocalPSModulePath = ${json} ? .PSModulePath
2188
+ if (-Not [String ]::IsNullOrEmpty($LocalPSModulePath )) {
2189
+ return $LocalPSModulePath
2190
+ }
2191
+ }
2192
+ $GlobalConfig = " $PSHOME \powershell.config.json"
2193
+ if (Test-Path - Path $GlobalConfig - PathType Leaf) {
2194
+ $json = Get-Content - LiteralPath $globalconfig - Raw | ConvertFrom-Json
2195
+ $GlobalPSModulePath = ${json} ? .PSModulePath
2196
+ if (-Not [String ]::IsNullOrEmpty($GlobalPSModulePath )) {
2197
+ $GlobalPSModulePath
2198
+ }
2199
+ }
2200
+ }
2162
2201
2163
2202
# endregion Helpers
2164
2203
0 commit comments