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

Does Windows PowerShell support powershell.config.json? #11349

Closed
o-l-a-v opened this issue Aug 23, 2024 · 2 comments
Closed

Does Windows PowerShell support powershell.config.json? #11349

o-l-a-v opened this issue Aug 23, 2024 · 2 comments
Labels
area-about Area - About_ topics resolution-answered Status - closed by existing documentation

Comments

@o-l-a-v
Copy link
Contributor

o-l-a-v commented Aug 23, 2024

Type of issue

Other (describe below)

Feedback

I tested using powershell.config.json for overriding PSModulePath like described here:

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

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_config?view=powershell-7.4#psmodulepath

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.4/Microsoft.PowerShell.Core/About/about_PowerShell_Config.md

Author

@sdwheeler

Document Id

91d350cb-6ac3-5a2e-b959-a9c8c1629c12

@sdwheeler
Copy link
Contributor

That's correct. Windows PowerShell doesn't support powershell.config.json. That's why the about_PowerShell_Config article doesn't exist in the 5.1 documentation. You were looking at the documentation for PowerShell 7.4.

@sdwheeler sdwheeler added resolution-answered Status - closed by existing documentation area-about Area - About_ topics and removed needs-triage Waiting - Needs triage labels Aug 23, 2024
@o-l-a-v
Copy link
Contributor Author

o-l-a-v commented Aug 23, 2024

@sdwheeler Thanks for the confirmation anyway. 🙂 Would be nice with a notice in the doc saying that 5.1 doesn't support it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-about Area - About_ topics resolution-answered Status - closed by existing documentation
Projects
None yet
Development

No branches or pull requests

2 participants