PSResourceGet
PSResourceGet copied to clipboard
Save-PSResource Path validation issues
Prerequisites
- [X] Write a descriptive title.
- [X] Make sure you are able to repro it on the latest released version
- [X] Search the existing issues.
Steps to reproduce
There is an issue with Path parameter for Save-PSResource, it seems like if you pass it a file instead of directory it does not throw an error and seems to be using the PWD to actually save the resource.
Expected behavior
Error is thrown that path is a file not a directory.
Actual behavior
PS C:\Temp> save-PSResource snmp -Path C:\test\abc.psd1 -AsNupkg -IncludeXML -Repository PSGallery
Save-PSResource: Unable to successfully install package 'SNMP': 'The file 'C:\Temp\snmp.1.0.0.1.nupkg' already exists.'
Error details
Exception :
Type : System.Management.Automation.PSInvalidOperationException
ErrorRecord :
Exception :
Type : System.Management.Automation.ParentContainsErrorRecordException
Message : Unable to successfully install package 'SNMP': 'The file 'C:\Temp\snmp.1.0.0.1.nupkg' already exists.'
HResult : -2146233087
CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException
FullyQualifiedErrorId : InvalidOperation
Message : Unable to successfully install package 'SNMP': 'The file 'C:\Temp\snmp.1.0.0.1.nupkg' already exists.'
InnerException :
Type : System.IO.IOException
TargetSite :
Name : CopyFile
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 file 'C:\Temp\snmp.1.0.0.1.nupkg' already exists.
Source : System.Private.CoreLib
HResult : -2147024816
StackTrace :
at System.IO.FileSystem.CopyFile(String sourceFullPath, String destFullPath, Boolean overwrite)
at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
at Microsoft.PowerShell.PowerShellGet.Cmdlets.InstallHelper.InstallPackage(List`1 pkgsToInstall, String repoName, String repoUri, PSCredentialInfo
repoCredentialInfo, PSCredential credential, Boolean isLocalRepo) in D:\a\_work\1\s\src\code\InstallHelper.cs:line 322
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 : 6
Line : save-PSResource snmp -Path C:\test\abc.psd1 -AsNupkg -IncludeXML -Repository PSGallery
PositionMessage : At line:1 char:1
+ save-PSResource snmp -Path C:\test\abc.psd1 -AsNupkg -IncludeXML -Rep …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : save-PSResource
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
Environment data
Name Version
---- -------
PowerShellGet 3.0.16
Name Value
---- -----
PSVersion 7.2.6
PSEdition Core
GitCommitId 7.2.6
OS Microsoft Windows 10.0.19044
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