'Errors installing SharePoint Online Management Shell behind a proxy

I have my virtual machine which is running Windows Server 2019. I installed SharePoint Online Management Shell and I got the following error when I opened the terminal:

Import-Module : Could not load type 'Microsoft.SharePoint.Client.Publishing.PortalLaunch.PortalLaunchRedirectionType'
from assembly 'Microsoft.SharePoint.Client.Publishing, Version=16.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c'.
At C:\WINDOWS\system32\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:2 char:1
+ Import-Module Microsoft.Online.SharePoint.PowerShell
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], TypeLoadException
    + FullyQualifiedErrorId : System.TypeLoadException,Microsoft.PowerShell.Commands.ImportModuleCommand
 

The company is using a proxy.

I tried the following:

$cred = Get.Credential
PS C:\WINDOWS\system32> [system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://.......')
PS C:\WINDOWS\system32> [system.net.webrequest]::defaultwebproxy.credentials = $cred
PS C:\WINDOWS\system32> [system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
PS C:\WINDOWS\system32> [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12

PS C:\WINDOWS\system32> [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

PS C:\WINDOWS\system32> Install-Module Microsoft.Online.SharePoint.PowerShell -force

I got this:

PS C:\WINDOWS\system32> **Install-Module Microsoft.Online.SharePoint.PowerShell -force**
WARNING: Unable to resolve package source 'https://www.powershellgallery.com/api/v2'.
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'Microsoft.Online.SharePoint.PowerShell'. Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
 
**PS C:\WINDOWS\system32> **Get-PSRepository****
 
Name                      InstallationPolicy   SourceLocation
----                      ------------------   --------------
PSGallery                 Trusted              https://www.powershellgallery.com/api/v2


**Get-ExecutionPolicy -List**
 
        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy    RemoteSigned
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser    Unrestricted
LocalMachine    Unrestricted

I have run out of ideas. Any help?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source