Skip to content

Publish-PSResource v1.1.1 to PSGallery errors out on a new windows server for the first run #1806

@afroz429

Description

@afroz429

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 new Windows server, Install Microsoft.PowerShell.PSResourceGet v1.1.1
  • Run Publish-PSResouce to publish to PSGallery.
Import-Module Microsoft.PowerShell.PSResourceGet
$commonArgs = @{
    'ApiKey'                     = '{key redacted}'
    'SkipDependenciesCheck'      = $true
    'SkipModuleManifestValidate' = $true
    'Repository'                 = 'PSGallery'
}
$modulePath = "C:\Users\albus\newmodule\root3i\root3i\root3i.psd1"
Publish-PSResource -Path $modulePath @commonArgs

Publish-PSResource v1.1.1 when publishing to PSGallery errors out on a new windows server for the first run with the error Publish-PSResource: Cannot retrieve the dynamic parameters for the cmdlet. Loading repository store failed: Could not find a part of the path 'C:\Users\albus\AppData\Local\PSResourceGet\PSResourceRepository.xml'.

Interestingly when Get-PSResourceRepository is run, the file PSResourceRepository.xml gets created and the Publish command runs fine after that. Even retrying Publish multiple times seems to work. See code below

PS C:\Users\albus> Get-ChildItem C:\Users\albus\AppData\Local\PSResourceGet\PSResourceRepository.xml
Get-ChildItem: Cannot find path 'C:\Users\albus\AppData\Local\PSResourceGet\PSResourceRepository.xml' because it does not exist.
PS C:\Users\albus> Get-PSResourceRepository

Name      Uri                                      Trusted Priority IsAllowedByPolicy
----      ---                                      ------- -------- -----------------
PSGallery https://www.powershellgallery.com/api/v2 False   50       True

PS C:\Users\albus> Get-ChildItem C:\Users\albus\AppData\Local\PSResourceGet\PSResourceRepository.xml

    Directory: C:\Users\albus\AppData\Local\PSResourceGet

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           3/12/2025  3:43 AM            204 PSResourceRepository.xml

Expected behavior

`Publish-PSResource` to PSGallery runs without errors

Actual behavior

Publish-PSResource to PSGallery errors out with `Publish-PSResource: Cannot retrieve the dynamic parameters for the cmdlet. Loading repository store failed: Could not find a part of the path 'C:\Users\albus\AppData\Local\PSResourceGet\PSResourceRepository.xml'.`

Error details

Exception             : 
    Type              : System.Management.Automation.ParameterBindingException
    Message           : Cannot retrieve the dynamic parameters for the cmdlet. Loading repository store failed: Could not find a part of the path 'C:\Users\albus\AppData\Local\PSResourceGet\PSResourceRepository.xml'.
    ErrorId           : GetDynamicParametersException
    Line              : 1
    Offset            : 1
    CommandInvocation : 
        MyCommand        : Publish-PSResource
        BoundParameters  : 
            Comparer : System.OrdinalIgnoreCaseComparer
            Count    : 5
            Capacity : 7
            Keys     : 
                              Path
                              ApiKey
                              Repository
                              SkipDependenciesCheck
                              SkipModuleManifestValidate
            Values   : 
                              C:\Users\albus\newmodule\root3i\root3i\root3i.psd1
                              {key redacted}
                              PSGallery

                IsPresent : True

                IsPresent : True
            SyncRoot : 
                Comparer : System.OrdinalIgnoreCaseComparer
                Count    : 5
                Capacity : 7
                Keys     : 
                                      Path
                                      ApiKey
                                      Repository
                                      SkipDependenciesCheck
                                      SkipModuleManifestValidate
                Values   : 
                                      C:\Users\albus\newmodule\root3i\root3i\root3i.psd1
                                      {key redacted}
                                      PSGallery

                    IsPresent : True

                    IsPresent : True
                SyncRoot : 
                    Comparer : System.OrdinalIgnoreCaseComparer
                    Count    : 5
                    Capacity : 7
                    Keys     : 
                                              Path
                                              ApiKey
                                              Repository
                                              SkipDependenciesCheck
                                              SkipModuleManifestValidate
                    Values   : 
                                              C:\Users\albus\newmodule\root3i\root3i\root3i.psd1
                                              {key redacted}
                                              PSGallery

                        IsPresent : True

                        IsPresent : True
                    SyncRoot : 
                        Comparer : System.OrdinalIgnoreCaseComparer
                        Count    : 5
                        Capacity : 7
                        Keys     : 
                                                      Path
                                                      ApiKey
                                                      Repository
                                                      SkipDependenciesCheck
                                                      SkipModuleManifestValidate
                        Values   : 
                                                      C:\Users\albus\newmodule\root3i\root3i\root3i.psd1
                                                      {key redacted}
                                                      PSGallery

                            IsPresent : True

                            IsPresent : True
                        SyncRoot : 
                            Comparer : System.OrdinalIgnoreCaseComparer
                            Count    : 5
                            Capacity : 7
                            Keys     : 
                                                              Path
                                                              ApiKey
                                                              Repository
                                                              SkipDependenciesCheck
                                                              SkipModuleManifestValidate
                            Values   : 
                                                              C:\Users\albus\newmodule\root3i\root3i\root3i.psd1
                                                              {key redacted}
                                                              PSGallery

                                IsPresent : True

                                IsPresent : True
                            SyncRoot : 
                                Comparer : System.OrdinalIgnoreCaseComparer
                                Count    : 5
                                Capacity : 7
                                Keys     : 
                                                                      Path
                                                                      ApiKey
                                                                      Repository
                                                                      SkipDependenciesCheck
                                                                      SkipModuleManifestValidate
                                Values   : 
                                                                      C:\Users\albus\newmodule\root3i\root3i\root3i.psd1
                                                                      {key redacted}
                                                                      PSGallery

                                    IsPresent : True

                                    IsPresent : True
                                SyncRoot : 
                                    Comparer : System.OrdinalIgnoreCaseComparer
                                    Count    : 5
                                    Capacity : 7
                                    Keys     : …
                                    Values   : …
                                    SyncRoot : …
        ScriptLineNumber : 1
        OffsetInLine     : 1
        HistoryId        : 11
        Line             : Publish-PSResource -Path $modulePath @commonArgs
        Statement        : Publish-PSResource -Path $modulePath @commonArgs
        PositionMessage  : At line:1 char:1
                           + Publish-PSResource -Path $modulePath @commonArgs
                           + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        InvocationName   : Publish-PSResource
        PipelineLength   : 1
        PipelinePosition : 1
    ErrorRecord       : 
        Exception             : 
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Cannot retrieve the dynamic parameters for the cmdlet. Loading repository store failed: Could not find a part of the path 'C:\Users\albus\AppData\Local\PSResourceGet\PSResourceRepository.xml'.
            HResult : -2146233087
        CategoryInfo          : InvalidArgument: (:) [Publish-PSResource], ParentContainsErrorRecordException
        FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource
        InvocationInfo        : 
            MyCommand        : Publish-PSResource
            ScriptLineNumber : 1
            OffsetInLine     : 1
            HistoryId        : 11
            Line             : Publish-PSResource -Path $modulePath @commonArgs
            Statement        : Publish-PSResource -Path $modulePath @commonArgs
            PositionMessage  : At line:1 char:1
                               + Publish-PSResource -Path $modulePath @commonArgs
                               + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite        : 
        Name          : HandleCommandLineDynamicParameters
        DeclaringType : [System.Management.Automation.CmdletParameterBinderController]
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Data              : System.Collections.ListDictionaryInternal
    InnerException    : 
        Type        : System.Management.Automation.PSInvalidOperationException
        ErrorRecord : 
            Exception             : 
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : Loading repository store failed: Could not find a part of the path 'C:\Users\albus\AppData\Local\PSResourceGet\PSResourceRepository.xml'.
                HResult : -2146233087
            CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : InvalidOperation
        TargetSite  : 
            Name          : Read
            DeclaringType : [Microsoft.PowerShell.PSResourceGet.UtilClasses.RepositorySettings]
            MemberType    : Method
            Module        : Microsoft.PowerShell.PSResourceGet.dll
        Message     : Loading repository store failed: Could not find a part of the path 'C:\Users\albus\AppData\Local\PSResourceGet\PSResourceRepository.xml'.
        Source      : Microsoft.PowerShell.PSResourceGet
        HResult     : -2146233079
        StackTrace  : 
   at Microsoft.PowerShell.PSResourceGet.UtilClasses.RepositorySettings.Read(String[] repoNames, String[]& errorList) in C:\__w\1\s\PSResourceGet\src\code\RepositorySettings.cs:line 574
   at Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource.GetDynamicParameters() in C:\__w\1\s\PSResourceGet\src\code\PublishPSResource.cs:line 125
   at System.Management.Automation.CmdletParameterBinderController.HandleCommandLineDynamicParameters(ParameterBindingException& outgoingBindingException)
    Source            : System.Management.Automation
    HResult           : -2146233087
    StackTrace        : 
   at System.Management.Automation.CmdletParameterBinderController.HandleCommandLineDynamicParameters(ParameterBindingException& outgoingBindingException)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
   at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
   at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
--- End of stack trace from previous location ---
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : InvalidArgument: (:) [Publish-PSResource], ParameterBindingException
FullyQualifiedErrorId : GetDynamicParametersException,Microsoft.PowerShell.PSResourceGet.Cmdlets.PublishPSResource
InvocationInfo        : 
    MyCommand        : Publish-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 11
    Line             : Publish-PSResource -Path $modulePath @commonArgs
    Statement        : Publish-PSResource -Path $modulePath @commonArgs
    PositionMessage  : At line:1 char:1
                       + Publish-PSResource -Path $modulePath @commonArgs
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.1.1                 Microsoft.PowerShell.PSResourceGet  {Compress-PSResource, Find-PSResource, Get-Instal…


Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions