Skip to content

Windows environment variables in powershell.scriptAnalysis.settingsPath #4268

Closed

Description

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.

Summary

I'd like to be able to use Windows environment variables inside settings.json powershell.scriptAnalysis.settingsPath.

From my testing it does not currently seem possible.

Why?

I'd like to be able to easily sync both Visual Studio Code settings.json and PSScriptAnalyzer settings file between devices.

Windows explorer

Path in Windows Explorer that resolves:

  • %OneDriveConsumer%\_Share\AppData\PowerShell\Settings-PSScriptAnalyzer.psd1

Settings.json

In settings.json I've tried the following.

Works (hard coded)

"powershell.scriptAnalysis.settingsPath": "C:/Users/<removed>/OneDrive/_Share/AppData/PowerShell/Settings-PSScriptAnalyzer.psd1"

Does not work

Neither of these works.

"powershell.scriptAnalysis.settingsPath": "${env:OneDriveConsumer}/_Share/AppData/PowerShell/Settings-PSScriptAnalyzer.psd1"
"powershell.scriptAnalysis.settingsPath": "${env:OneDriveConsumer}\\_Share\\AppData\\PowerShell\\Settings-PSScriptAnalyzer.psd1"
"powershell.scriptAnalysis.settingsPath": "${userHome}/OneDrive/Share/AppData/PowerShell/Settings-PSScriptAnalyzer.psd1"
"powershell.scriptAnalysis.settingsPath": "${userHome}\\OneDrive\\Share\\AppData\\PowerShell\\Settings-PSScriptAnalyzer.psd1"
"powershell.scriptAnalysis.settingsPath": "%OneDriveConsumer%/_Share/AppData/PowerShell/Settings-PSScriptAnalyzer.psd1"
"powershell.scriptAnalysis.settingsPath": "%OneDriveConsumer%\\_Share\\AppData\\PowerShell\\Settings-PSScriptAnalyzer.psd1"

Proposed Design

  • Add this ability if it does not exist already
    • Preferably in the same syntax used for environment variables inside the terminal.integrated.profiles.windows setting.
      • Example: "path": "${env:LOCALAPPDATA}\\Microsoft\\WindowsApps\\Microsoft.PowerShell_8wekyb3d8bbwe\\pwsh.exe"
  • Document how to use it
    • Path separator?
      • \, \\, /
      • Does it vary per OS?
    • How to represent a environmental variable?
      • %APPDATA%, ${APPDATA}, ${env:APPDATA}
      • Does it vary per OS?

Relevant doc

Activity

  1. ghost added
    Needs: TriageMaintainer attention needed!
    on Nov 17, 2022
  2. andyleejordan commented on Nov 30, 2022

    @andyleejordan
    Member

    Unfortunately, extension-provided settings such as this are explicitly not parsed for variable resolution by VS Code, and doing so in a post-processing manner would be quite difficult to get right. It's a neat idea, and I see the desire for it, but probably not something we're prioritizing at this point.

    I would point you toward VS Code setting profiles as a different approach to solve your problem.

  3. andyleejordan commented on Dec 7, 2022

    @andyleejordan
    Member

    Please see microsoft/vscode#46471 for more context as to my contributed settings (like ours) can't support VS Code built-in (nor environment, through env:) variables.

  4. ghost closed this as completedon Dec 7, 2022
  5. o-l-a-v commented on Jun 17, 2024

    @o-l-a-v
    ContributorAuthor

    In case it help others: I've got this working using a symlink from %PUBLIC%\PSSCriptAnalyzer.psd1, which will be the same path on multiple systems. I symlinked it like so:

    # Assets
    $Source      = [string] '{0}\PSScriptAnalyzer.psd1' -f $env:PUBLIC
    $Destination = [string] '{0}\_Share\AppData\PowerShell\Settings - PSScriptAnalyzer.psd1' -f $env:OneDriveConsumer
    
    # Create symlink (requires admin unless Windows developer mode is enabled)
    New-Item -ItemType 'SymbolicLink' -Path $Source -Value $Destination -Force

    Then in VSCode settings.json:

    {
      ...
      "powershell.scriptAnalysis.settingsPath": "C:\\Users\\Public\\PSScriptAnalyzer.psd1",
      ...
    }

    I'd prefer if VSCode could use environment variables inside VSCode settings.json:

    Or the ability to configure PSScriptAnalyzer for vscode-powershell inside VSCode settings.json:

  6. o-l-a-v commented on Nov 17, 2026

    @o-l-a-v
    ContributorAuthor

    Andy Jordan (@andyleejordan)

    The VSCode Python extension accepts env variables. This works.

    {
      "python.defaultInterpreterPath": "${env:USERPROFILE}/scoop/apps/python/current/python.exe"
    }

    This code looks relevant:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions