You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is using the latest stable version "1.4.6" of "PackageManagement" as of 2020-02-26 on Windows PowerShell 5.1
I've found that when errors happen in "Get-InstalledModule" and "Uninstall-Module" commands, errors is not added to $Error variable, and $? is not set to false unless $ErrorActionPreference is set to 'Stop'. Also, reading the error messages, I see that reported commandlet ran according to the error messages added to the terminal, are "PackageManagement\Uninstall-Package" for "Uninstall-Module" and "PackageManagement\Get-Package" for "Get-InstalledModule". When using these commands, $? is righfully set to $false if they fail, but these commands are not adding error to $Error either.
Code to reproduce (designed to run line per line)
# Settings## PowerShell Preferences$ErrorActionPreference='Continue'# Default for new PowerShell session# PackageManagement## ImportImport-Module-Name 'PackageManagement'-Force
## Output imported version of the module$(Get-Module-Name 'PackageManagement').'Version'.ToString()
# Assets## Fictive module$Name='SomeModuleName'$Version='1.2.3'# Get## Using "Get-InstalledModule"Get-InstalledModule-Name $Name-RequiredVersion $Version$?$Error[0]
## Using "PackageManagement\Get-Package"PackageManagement\Get-Package-Name $Name-RequiredVersion $Version$?$Error[0]
# Uninstall## Using "Uninstall-Module"Uninstall-Module-Name $Name-RequiredVersion $Version$?$Error[0]
## Using "PackageManagement\Uninstall-Package"PackageManagement\Uninstall-Package-Name $Name-RequiredVersion $Version$?$Error[0]
Output showing wrong cmdlet is reported in the error + $? is not set correctly.
PS C:\Users\olavb>$ErrorActionPreference='Continue'# Default for new PowerShell session
PS C:\Users\olavb>Import-Module-Name 'PackageManagement'-Force
PS C:\Users\olavb>$(Get-Module-Name 'PackageManagement').'Version'.ToString()
1.4.6
PS C:\Users\olavb>$Name='SomeModuleName'$Version='1.2.3'
PS C:\Users\olavb>Get-InstalledModule-Name $Name-RequiredVersion $VersionPackageManagement\Get-Package : No match was found for the specified search criteria and module names 'SomeModuleName'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.3\PSModule.psm1:9423 char:9+PackageManagement\Get-Package@PSBoundParameters| Microsoft. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage
PS C:\Users\olavb>$?
True
PS C:\Users\olavb>PackageManagement\Get-Package-Name $Name-RequiredVersion $VersionPackageManagement\Get-Package : No package found for'SomeModuleName'.
At line:1 char:1+PackageManagement\Get-Package-Name $Name-RequiredVersion $Version+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...lets.GetPackage:GetPackage) [Get-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackage
PS C:\Users\olavb>$?
False
PS C:\Users\olavb>Uninstall-Module-Name $Name-RequiredVersion $VersionPackageManagement\Uninstall-Package : No match was found for the specified search criteria and module names 'SomeModuleName'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.3\PSModule.psm1:12657 char:21+ ...$null=PackageManagement\Uninstall-Package@PSBoundParameters+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
PS C:\Users\olavb>$?
True
PS C:\Users\olavb>PackageManagement\Uninstall-Package-Name $Name-RequiredVersion $VersionPackageManagement\Uninstall-Package : No package found for'SomeModuleName'.
At line:1 char:1+PackageManagement\Uninstall-Package-Name $Name-RequiredVersion $Ver ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power...ninstallPackage:UninstallPackage) [Uninstall-Package], Exception
+ FullyQualifiedErrorId : NoMatchFound,Microsoft.PowerShell.PackageManagement.Cmdlets.UninstallPackage
PS C:\Users\olavb>$?
False
PS C:\Users\olavb>
This all works for the "Find-Package" command.
The text was updated successfully, but these errors were encountered:
o-l-a-v
changed the title
"Get-InstalledModule" and "Uninstall-Module" errors is not added to $Error and does not set $? to $false
"Get-InstalledModule" and "Uninstall-Module" errors does not set $? to $false
Feb 26, 2020
o-l-a-v
changed the title
"Get-InstalledModule" and "Uninstall-Module" errors does not set $? to $false
"Get-InstalledModule" and "Uninstall-Module" errors do not set $? to $false
Feb 26, 2020
This is using the latest stable version "1.4.6" of "PackageManagement" as of 2020-02-26 on Windows PowerShell 5.1
I've found that when errors happen in "Get-InstalledModule" and "Uninstall-Module" commands, errors is not added to$Error variable, and $ ? is not set to false unless $ErrorActionPreference is set to 'Stop'. Also, reading the error messages, I see that reported commandlet ran according to the error messages added to the terminal, are "PackageManagement\Uninstall-Package" for "Uninstall-Module" and "PackageManagement\Get-Package" for "Get-InstalledModule". When using these commands, $ ? is righfully set to $false if they fail, but these commands are not adding error to $Error either.
Code to reproduce (designed to run line per line)
Output showing wrong cmdlet is reported in the error + $? is not set correctly.
This all works for the "Find-Package" command.
The text was updated successfully, but these errors were encountered: