Skip to content

Set-PSResourceRepository fails on first run when PSResourceGet store directory does not exist #1965

@yaegashi

Description

@yaegashi

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.

Steps to reproduce

On a fresh Linux environment where the PSResourceGet store directory does not exist, run the following:

Import-Module Microsoft.PowerShell.PSResourceGet
Remove-Item -Recurse -Force /home/vscode/.local/share/PSResourceGet -ErrorAction SilentlyContinue
Set-PSResourceRepository -Name PSGallery -Trusted

I also encountered this during a brand new GitHub Codespaces/devcontainer build, where postCreateCommand runs Set-PSResourceRepository -Name PSGallery -Trusted. A minimal first-run repro is enough to trigger the same problem

Observed notes:

  • Get-PSResourceRepository can return the default PSGallery repository.
  • Set-PSRepository -Name PSGallery -InstallationPolicy Trusted does not fail in the same environment.
  • Creating the parent directory manually makes the PSResourceGet command succeed:
    mkdir -p /home/vscode/.local/share/PSResourceGet
    After that, this succeeds:
    Set-PSResourceRepository -Name PSGallery -Trusted

Expected behavior

Set-PSResourceRepository should succeed on first run and create any missing parent directory or repository store file needed for PSResourceGet state.

Actual behavior

Set-PSResourceRepository fails before it can initialize the repository store:

Cannot retrieve the dynamic parameters for the cmdlet. Loading repository store failed: Could not find a part of the path '/home/vscode/.local/share/PSResourceGet/PSResourceRepository.xml'.


In the devcontainer build log, the same failure aborts postCreateCommand entirely:

2026-03-19 02:43:19.647Z: Running the postCreateCommand from devcontainer.json...
2026-03-19 02:43:19.647Z: pwsh .devcontainer/install-dev-tools.ps1 && bash ./.devcontainer/workspace-repositories-clone.sh
2026-03-19 02:43:20.940Z: Set-PSResourceRepository: /workspaces/excloud-runbooks-ghemu/.devcontainer/install-dev-tools.ps1:5
Line |
   5 |  Set-PSResourceRepository -Name PSGallery -Trusted
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot retrieve the dynamic parameters for the cmdlet. Loading
     | repository store failed: Could not find a part of the path
     | '/home/vscode/.local/share/PSResourceGet/PSResourceRepository.xml'.
2026-03-19 02:43:21.041Z: postCreateCommand from devcontainer.json failed with exit code 1. Skipping any further user-provided commands.

Error details

PSMessageDetails      : 
Exception             : System.Management.Automation.ParameterBindingException:
                         Cannot retrieve the dynamic parameters for the 
                        cmdlet. Loading repository store failed: Could not 
                        find a part of the path '/home/vscode/.local/share/PSRe
                        sourceGet/PSResourceRepository.xml'.
                         ---> System.Management.Automation.PSInvalidOperationEx
                        ception: Loading repository store failed: Could not 
                        find a part of the path '/home/vscode/.local/share/PSRe
                        sourceGet/PSResourceRepository.xml'.
                           at Microsoft.PowerShell.PSResourceGet.UtilClasses.Re
                        positorySettings.Read(String[] repoNames, String[]& 
                        errorList) in C:\__w\1\s\PSResourceGet\src\code\Reposit
                        orySettings.cs:line 603
                           at Microsoft.PowerShell.PSResourceGet.Cmdlets.SetPSR
                        esourceRepository.GetDynamicParameters() in C:\__w\1\s\
                        PSResourceGet\src\code\SetPSResourceRepository.cs:line 
                        112
                           at System.Management.Automation.CmdletParameterBinde
                        rController.HandleCommandLineDynamicParameters(Paramete
                        rBindingException& outgoingBindingException)
                           --- End of inner exception stack trace ---
                           at System.Management.Automation.ExceptionHandlingOps
                        .CheckActionPreference(FunctionContext funcContext, 
                        Exception exception)
                           at System.Management.Automation.Interpreter.ActionCa
                        llInstruction`2.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTry
                        CatchFinallyInstruction.Run(InterpretedFrame frame)
                           at System.Management.Automation.Interpreter.EnterTry
                        CatchFinallyInstruction.Run(InterpretedFrame frame)
TargetObject          : 
CategoryInfo          : InvalidArgument: (:) [Set-PSResourceRepository], 
                        ParameterBindingException
FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.PSRe
                        sourceGet.Cmdlets.SetPSResourceRepository
ErrorDetails          : 
InvocationInfo        : System.Management.Automation.InvocationInfo
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {}

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.2.0                 Microsoft.PowerShell.PSResourceGet  {Compress-PSResource, Find-PSResource, Get-InstalledPSResource, Get-PSResourceRepository…}

Name                           Value
----                           -----
PSVersion                      7.6.0
PSEdition                      Core
GitCommitId                    7.6.0
OS                             Ubuntu 24.04.4 LTS
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.4
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

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