Skip to content

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

Closed
@o-l-a-v

Description

@o-l-a-v

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-aboutArea - About_ topicsresolution-answeredStatus - closed by existing documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions