PowerShell error when updating PowerCLI to latest version

PowerShell error when updating PowerCLI to latest version

These days I wanted to update a PowerCLI installation to current version. Normally this no big deal. But this time I got a PowerShell error when updating PowerCLI. I was using this command:

 Update-Module vmware.powercli 

and got the following error:

powershell error update powercli


PackageManagement\Install-Package : Unable to find repository 'https://www.powershellgallery.com/api/v2/'. Use Get-PSRepository to see all available repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.0.1\PSModule.psm1:13000 char:20
+ ... $sid = PackageManagement\Install-Package @PSBoundParameters
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
+ FullyQualifiedErrorId : SourceNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

Searching the repository using

 Find-Module vmware*

worked fine. Even updating PowerShellGet running

 Update-Module PowerShellGet

Module worked without a problem.

When running

 Get-PSRepository

I got:

Update_2.png

Name      InstallationPolicy SourceLocation
----      ------------------ --------------
PSGallery Untrusted          https://www.powershellgallery.com/api/v2

At first glance everything seems to be all right. But, Update-Module searches for location https://www.powershellgallery.com/api/v2/ , and PSGallery is registered by using location https://www.powershellgallery.com/api/v2. Without the slash “/” at the end.

My quick workaround is to register PSGallery a second time:

Register-PSRepository -Name "PSgallery2" -SourceLocation "https://www.powershellgallery.com/api/v2/" -InstallationPolicy Trusted

After this Update-Module vmware.powercli works fine!

Notes

  • Error can also by caused by security protocol configuration in PowerShell. See here.

Leave a Reply

Your email address will not be published. Required fields are marked *