Closed
Description
Type of issue
Other (describe below)
Feedback
I tested using powershell.config.json
for overriding PSModulePath like described here:
- https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_config#PSModulePath
- Allow to specify custom module path in Install-PSResource PowerShell/PSResourceGet#1494 (comment)
I created the file this resolves to in both pwsh.exe and powershell.exe:
[System.IO.Path]::Combine(
[System.IO.Directory]::GetParent($PROFILE.'CurrentUserCurrentHost').'FullName',
'powershell.config.json'
)
With following content:
{
"PSModulePath": "%LOCALAPPDATA%\\Microsoft\\PowerShell\\Modules2"
}
I then loaded pwsh.exe -NoProfile
:
PowerShell 7.4.5
PS C:\Users\olav.birkeland> $env:PSModulePath.Split(';')
C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules2
C:\Program Files\PowerShell\Modules
c:\program files\powershell\7\Modules
C:\Users\olav.birkeland\scoop\modules
C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules
C:\Users\olav.birkeland\OneDrive - Innovasjon Norge\Documents\PowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PS C:\Users\olav.birkeland>
But with powershell.exe
it does not seem to work:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows
PS C:\Users\olav.birkeland> $env:PSModulePath.Split(';')
C:\Users\olav.birkeland\scoop\modules
C:\Users\olav.birkeland\AppData\Local\Microsoft\PowerShell\Modules
C:\Users\olav.birkeland\OneDrive - Innovasjon Norge\Documents\PowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PS C:\Users\olav.birkeland>
I then found following package on PowerShell Gallery:
It has a check that throws and error if not PowerShell Core:
if (-Not $IsCoreCLR) {
throw 'Windows PowerShell does not use powershell.config.json configuration files.'
}
So, it seems to me Windows PowerShell / powershell.exe does not support powershell.config.json? 🤔
Page URL
Content source URL
Author
Document Id
91d350cb-6ac3-5a2e-b959-a9c8c1629c12