Skip to content

Save-PSResource fails when current directory is not a file system provider and no path parameter is passed #702

@ThomasNieto

Description

@ThomasNieto

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

If the current directory is not a file system provider path Save-PSResource looks to be getting the user's home path and appending the current path to it instead of just using the file system provider path.

cd c:\temp\test
cd HKLM:\

PS HKLM:\> Get-Location -PSProvider FileSystem

Path
----
C:\Temp\test

Save-PSResource abc -PassThru

To resolve this issue the Path parameter default value should be: $ExecutionContext.SessionState.Path.CurrentFileSystemLocation

Expected behavior

Saves resource to C:\temp\test

Actual behavior

PS HKLM:\> Save-PSResource abc -PassThru
Save-PSResource: Unable to successfully install package 'ABC': 'The filename, directory name, or volume label syntax is incorrect. : 'C:\Users\Thomas\HKLM:\ABC''

Error details

Exception             :
    Type           : System.Management.Automation.PSInvalidOperationException
    ErrorRecord    :
        Exception             :
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Unable to successfully install package 'ABC': 'The filename, directory name, or volume label
syntax is incorrect. : 'C:\Users\Thomas\HKLM:\ABC''
            HResult : -2146233087
        CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
        FullyQualifiedErrorId : InvalidOperation
    Message        : Unable to successfully install package 'ABC': 'The filename, directory name, or volume label
syntax is incorrect. : 'C:\Users\Thomas\HKLM:\ABC''
    InnerException :
        Type       : System.IO.IOException
        TargetSite :
            Name          : CreateDirectory
            DeclaringType : System.IO.FileSystem, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral,
PublicKeyToken=7cec85d7bea7798e
            MemberType    : Method
            Module        : System.Private.CoreLib.dll
        Message    : The filename, directory name, or volume label syntax is incorrect. : 'C:\Users\Thomas\HKLM:\ABC'
        Source     : System.Private.CoreLib
        HResult    : -2147024773
        StackTrace :
   at System.IO.FileSystem.CreateDirectory(String fullPath, Byte[] securityDescriptor)
   at System.IO.Directory.CreateDirectory(String path)
   at Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallHelper.MoveFilesIntoInstallPath(PSResourceInfo pkgInfo,
Boolean isModule, Boolean isLocalRepo, String dirNameVersion, String tempInstallPath, String installPath, String
newVersion, String moduleManifestVersion, String scriptPath) in D:\a\_work\1\s\src\code\InstallHelper.cs:line 846
   at Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallHelper.InstallPackage(IEnumerable`1 pkgsToInstall, String
repoName, String repoUri, PSCredentialInfo repoCredentialInfo, PSCredential credential, Boolean isLocalRepo) in
D:\a\_work\1\s\src\code\InstallHelper.cs:line 543
    HResult        : -2146233079
TargetObject          : Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource
CategoryInfo          : InvalidOperation: (Microsoft.PowerShel…lets.SavePSResource:SavePSResource) [Save-PSResource],
PSInvalidOperationException
FullyQualifiedErrorId : InstallPackageFailed,Microsoft.PowerShell.PowerShellGet.Cmdlets.SavePSResource
InvocationInfo        :
    MyCommand        : Save-PSResource
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 36
    Line             : Save-PSResource abc -PassThru
    PositionMessage  : At line:1 char:1
                       + Save-PSResource abc -PassThru
                       + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Save-PSResource
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :

Environment data

Name          Version
----          -------
PowerShellGet 3.0.14

Name                           Value
----                           -----
PSVersion                      7.2.5
PSEdition                      Core
GitCommitId                    7.2.5
OS                             Microsoft Windows 10.0.19043
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

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions