Menu

Virtual Geek

Tales from real IT system administrators world and non-production environment

Powershell Azure Az module Install-Package cannot convert value 2.0.0-preview to type system.version

While installing/upgrading Azure PowerShell az module I faced below error. I was using Powershell Desktop Version 5.1 and it by default comes with Windows 10 OS. I cannot install PowerShell Core (another application) due to restrictions. So thought of using whatever I have on my received laptop.

Install-Module az -Force
PackageManagement\Install-Package : Cannot convert value "2.0.0-preview" to type "System.Version". Error: "Input string was no in a correct format."
At C:\Program Files\WindowsPowerShell\Modules\PowershellGet\1.0.0.1\PSModule.psm1:1890 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+
    + CategoryInfo          : InvalidArgument: (Microsoft.Power....InstallPacakage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : InvalidCastParseTargetInvocation,New-PSGetItemInfo,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Whenever you install any module from PowerShell repository it uses PowershellGet and PackageManagement modules to get task done in the background and it auto loaded module when required. Once I verify listing modules with below commands, It shows me the version 1.0.0.1 is very initial one for PowershellGet. After finding related modules from internet psgallery repository. I see latest version available online versions are PowershellGet 2.2.3 and PackageManagement 1.4.6. (This requires Admin Access).

Get-Module -ListAvailable PowershellGet, PackageManagement
Find-Module PowershellGet -IncludeDependencies

In next instructions install latest versions.

Powershell Azure install-module az -force Get-module -listavailable PowershellGet, PackageManagement Find-Module Install-Package Error Input string was not in a correct format.png

Next install PowershellGet module, it will install latest version and dependent module PackageManagement as shown in the below commands. You cannot completely uninstall initial version of module using (Uninstall-Module). but they can co-exist with each other. What can be done is we can stop using older version with Remove-Module PackageManagement, PowershellGet -Force to unload it.

Install-Module PowershellGet -Force
Get-Module PackageManagement, PowerShellGet
Get-Module PackageManagement, PowerShellGet -ListAvailable

To verify use with and without -ListAvailable parameter using Get-Module to compare which modules are available and loaded.

Install-Module PowershellGet -Force Get-Module PackageManagement, PowerShellGet -listAvailable powershell azure az module error.png

In the last try installing az module, I am using it to install to logged in Current User profile only, Once az module is downloaded, it is not auto loaded until you use Az related comdlets/functions/scripts, to get list use -ListAvailable parameter using Get-Module command.

Install-Module az -Scope CurrentUser
Get-Module az
Get-Module -ListAvailable

Install-Module az -scope currentUser  get-module az -listavailable get-module az -listavailable error installing azure powershell modules.png

Useful Articles
PART 1 : MICROSOFT AZURE CREATION AND CONFIGURATION OF VPN TUNNEL SERIES
PART 2 : MICROSOFT AZURE CREATING RESOURCE GROUP 
PART 3 : MICROSOFT AZURE CREATING AND ADMINISTERING VIRTUAL NETWORK (VNET) 
PART 3.1 : MICROSOFT AZURE POWERSHELL CREATING AND ADMINISTERING VIRTUAL NETWORK (VNET)

Go Back

Comment

Blog Search

Page Views

12278762

Follow me on Blogarama