PSResourceGet
PSResourceGet copied to clipboard
Save-PSResource script fails
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
Save-PSResource works for modules.
PS> Save-PSResource Az
Save-PSResource: The 'file' scheme is not supported.
Note: That bit about the 'file' scheme not being supported is caused by having a local directory registered as a repository. This is a separate concern and unrelated to the problem here, as I've tested on multiple machines, some without this local repository.
Save-PSResource for scripts fails.
PS> Save-PSResource New-OnPremiseHybridWorker
Save-PSResource: The 'file' scheme is not supported.
Save-PSResource: Unable to successfully install package 'New-OnPremiseHybridWorker': 'Could not find file 'C:\Users\***\AppData\Local\Temp\1\2b1ede54-ff18-4731-bfbb-d48de23466df\new-onpremisehybridworker\1.7\New-OnPremiseHybridWorker_InstalledScriptInfo.xml'.'
Save-PSResource: Operation is not valid due to the current state of the object.
Save-PSResource: Package(s) 'New-OnPremiseHybridWorker' could not be installed from registered repositories 'LocalPSGallery, PSGallery'.
The multiple repositories is not the cause. I get the same behavior on other machines with only PSGallery registered. Most of the messages are very poor. In particular "Operation is not valid due to the current state of the object." is developer speak and totally useless to most PowerShell users. The error reporting here should be vastly improved. The first message about the missing XML file does give a slight clue here, however, and the following "works" by some definition.
PS> Save-PSResource New-OnPremiseHybridWorker -IncludeXml
Save-PSResource: The 'file' scheme is not supported.
This saves the script, but also saves the XML metadata file. I'm not sure why you'd want that file, ever? Regardless, this is different behavior from saving a module. While not fully understanding the desired behavior of these cmdlets (I've posted a question in the discussions, but it appears literally no one reads or at least responds there) I would consider this to be a bug. At best it's inconsistent and unintuitive behavior, making it a usability bug, but I suspect this isn't really the expected behavior.
Expected behavior
PS> Save-PSResource New-OnPremiseHybridWorker
The New-OnPremiseHybridWorker.ps1 script should be saved to the current location without the XML metadata file.
### Actual behavior
```console
PS> Save-PSResource New-OnPremiseHybridWorker
Save-PSResource: Unable to successfully install package 'New-OnPremiseHybridWorker': 'Could not find file 'C:\Users\***\AppData\Local\Temp\1\2b1ede54-ff18-4731-bfbb-d48de23466df\new-onpremisehybridworker\1.7\New-OnPremiseHybridWorker_InstalledScriptInfo.xml'.'
Save-PSResource: Operation is not valid due to the current state of the object.
Save-PSResource: Package(s) 'New-OnPremiseHybridWorker' could not be installed from registered repositories 'LocalPSGallery, PSGallery'.
### Error details
```console
Exception :
Type : Microsoft.PowerShell.PSResourceGet.UtilClasses.ResourceNotFoundException
Message : Package(s) 'New-OnPremiseHybridWorker' could not be installed from repository 'PSGallery'.
HResult : -2146233088
TargetObject : Microsoft.PowerShell.PSResourceGet.Cmdlets.SavePSResource
CategoryInfo : InvalidData: (Microsoft.PowerShel…lets.SavePSResource:SavePSResource) [Save-PSResource],
ResourceNotFoundException
FullyQualifiedErrorId : InstallPackageFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.SavePSResource
InvocationInfo :
MyCommand : Save-PSResource
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 10
Line : save-psresource New-OnPremiseHybridWorker -Repository PSGallery
Statement : save-psresource New-OnPremiseHybridWorker -Repository PSGallery
PositionMessage : At line:1 char:1
+ save-psresource New-OnPremiseHybridWorker -Repository PSGallery
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
InvocationName : save-psresource
CommandOrigin : Internal
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo :
Environment data
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Binary 1.0.3 Microsoft.PowerShell.PSResourceGet {Find-PSResource, Get-InstalledPSResource, Get-PS…
Name Value
---- -----
PSVersion 7.4.1
PSEdition Core
GitCommitId 7.4.1
OS Microsoft Windows 10.0.19045
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