-
Notifications
You must be signed in to change notification settings - Fork 98
Save-PSResource with -WhatIf gives unexpected terminating error #1788
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Should it though? Also, I can't reproduce. PS > Save-PSResource -Name 'WSManDsc' -Path ([System.Environment]::GetFolderPath('Desktop') + '\Tes') -Debug -Verbose -WhatIf
DEBUG: In SavePSResource::ProcessSaveHelper()
DEBUG: In InstallHelper::BeginInstallPackages()
DEBUG: Parameters passed in >>> Name: 'WSManDsc'; VersionRange: ''; NuGetVersion: ''; VersionType: 'NoVersion'; Version: ''; Prerelease: 'False'; Repository: ''; AcceptLicense: 'False'; Quiet: 'False'; Reinstall: 'True'; TrustRepository: 'False'; NoClobber: 'False'; AsNupkg: 'False'; IncludeXml 'False'; SavePackage 'True'; TemporaryPath ''; SkipDependencyCheck: 'False'; AuthenticodeCheck: 'False'; PathsToInstallPkg: 'C:\Users\olav.birkeland\Desktop\Tes'; Scope ''
DEBUG: In InstallHelper::ProcessRepositories()
VERBOSE: Attempting to search for packages in 'PSGallery'
DEBUG: In InstallHelper::InstallPackages()
DEBUG: In InstallHelper::InstallPackage()
DEBUG: In V2ServerAPICalls::FindName()
DEBUG: In V2ServerAPICalls::HttpRequestCall()
DEBUG: Request url is 'https://www.powershellgallery.com/api/v2/FindPackagesById()?%24filter=Id+eq+%27WSManDsc%27+and+IsLatestVersion+eq+true&%24inlinecount=allpages&id=%27WSManDsc%27'
What if: Performing the operation "Save-PSResource" on target "Package to save: 'WSManDsc', version: '3.2.0'".
VERBOSE: Attempting to delete 'C:\Users\olav.birkeland\AppData\Local\Temp\f1077e38-c7f5-4b28-b0b7-d464dc4ca3ff'
VERBOSE: Successfully deleted 'C:\Users\olav.birkeland\AppData\Local\Temp\f1077e38-c7f5-4b28-b0b7-d464dc4ca3ff'
PS > |
@o-l-a-v You're right, I should have payed more attention while writing. I've changed the title and description. |
Whats the output with |
|
Ah. I think this is fixed in v1.1.0 stable, seems you are using v1.1.0-preview2? |
I thought v1.1.0 was shipped with v7.5.0? If I have both on there, shouldn't v1.1.0 be the one to overrule? My module loading knowledge is a bit rusty. |
From the "Environment data" section of the original post it says I've noticed that module loading is a can of worms. PowerShell will search though paths by the order of
So in some of my scripts I've implemented a workaround. Something like this: $PsrgConflictingAssembly = [object](
[Threading.Thread]::GetDomain().GetAssemblies().Where{
-not [string]::IsNullOrEmpty($_.'Location') -and
$_.'Location'.Contains('PSResourceGet') -and
$_.'ManifestModule'.'Name' -eq 'Microsoft.PowerShell.PSResourceGet.dll'
}[0]
)
if ([string]::IsNullOrEmpty($PsrgConflictingAssembly.'ManifestModule'.'Name')) {
[System.Environment]::SetEnvironmentVariable(
'PSModulePath',
[System.Environment]::ExpandEnvironmentVariables(
[System.Environment]::GetEnvironmentVariable('PSModulePath','User')
),
'Process'
)
$null = Import-Module -Name 'Microsoft.PowerShell.PSResourceGet'
}
else {
Import-Module -Name $PsrgConflictingAssembly.'ManifestModule'.'FullyQualifiedName'
} |
That's pretty slick @o-l-a-v. Thanks for the response. I'll close this one. Sorry for the duplicate. |
No problem. :) One can also load module by full path. Or remove paths from |
@Gijsreyn: Now I finally remember why this happens. I made a easy repro here: PowerShell/PowerShell#21201 (comment) It's very annoying indeed. 😑 |
Thanks for the share and providing such detail. |
Prerequisites
Steps to reproduce
Whenever adding the
-WhatIf
switch when saving a PowerShell module, the module doesn't give the what if response correctly. Instead, it terminates.Steps to reproduce:
Run:
Save-PSResource -Name WSManDsc -Path C:\temp -WhatIf
Expected behavior
Provide details about what if
Actual behavior
Gives both what if results and terminates.
Error details
Save-PSResource: Package(s) 'WSManDsc' could not be installed from repository 'PSGallery'.
Environment data
Visuals
No response
The text was updated successfully, but these errors were encountered: