How to install PowerShell Module?



There are two methods to install PowerShell modules. Online and Offline.

Online Method

This method is just like downloading the online package through Yum in the Unix system.

We first need to search the package available on the internet using the Find-Module command. You can use the wildcard character if you don’t know the full module name. All the packages are downloaded from PowerShell Gallery (https://www.powershellgallery.com/).

For example, if you want a Vmware PowerCLI module and you don’t know the full module name then just use the part of the name inside the Wildcard character(*).

Find-Module *vmware* | Select Name, Version, Repository
Name                            Version          Repository ----                            -------          ---------- VMware.VimAutomation.Sdk       12.0.0.15939651    PSGallery VMware.VimAutomation.Core      12.0.0.15939655    PSGallery VMware.VimAutomation.Common    12.0.0.15939652    PSGallery VMware.VimAutomation.Cis.Core  12.0.0.15939657    PSGallery VMware.Vim                     7.0.0.15939650     PSGallery VMware.VimAutomation.Vds       12.0.0.15940185    PSGallery VMware.VimAutomation.Srm       11.5.0.14899557    PSGallery VMware.VimAutomation.License   12.0.0.15939670    PSGallery VMware.VimAutomation.vROps     12.0.0.15940184    PSGallery VMware.VimAutomation.Cloud     12.0.0.15940183    PSGallery VMware.ImageBuilder            7.0.0.15902843     PSGallery VMware.VimAutomation.Nsxt      12.0.0.15939671    PSGallery VMware.PowerCLI                12.0.0.15947286    PSGallery VMware.VimAutomation.Horiz...  7.12.0.15718406    PSGallery VMware.VimAutomation.Storage   12.0.0.15939648    PSGallery VMware.DeployAutomation        7.0.0.15902843     PSGallery VMware.VimAutomation.Vmc       12.0.0.15947287    PSGallery VMware.VumAutomation           6.5.1.7862888      PSGallery VMware.VimAutomation.Stora...  1.3.0.0            PSGallery VMware.VimAutomation.Security  12.0.0.15939672    PSGallery VMware.VimAutomation.Hcx       12.0.0.15939647    PSGallery VMware.VimAutomation.HA        6.5.4.7567193      PSGallery VMware.VimAutomation.PCloud    10.0.0.7893924     PSGallery VMware.CloudServices           12.0.0.15947289    PSGallery VMware.VimAutomation.Workl... 12.0.0.15947288     PSGallery

Now we have a list of VMware modules available and we need Vmware.PowerCLI module among them. To install the module we will use Install-Module cmdlet.

Find-Module Vmware.PowerCLI | Install-Module
Untrusted repository You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the SetPSRepository cmdlet. Are you sure you want to install the modules from 'https://www.powershellgalle ry.com/api/v2/'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"):

You can check if the module is installed or not using the Get-Module command.

PS C:\WINDOWS\system32> Get-Module -Name *vmware* -ListAvailable | Select Name, Version Name                         Version ----                         ------- VMware.CloudServices          12.0.0.15947289 VMware.DeployAutomation       7.0.0.15902843 VMware.DeployAutomation       6.5.1.5299608 VMware.ImageBuilder           7.0.0.15902843 VMware.ImageBuilder           6.5.1.5299608 vmware.powercli               12.0.0.15947286 VMware.Vim                    7.0.0.15939650 VMware.VimAutomation.Cis.Core 6.5.1.5374323 VMware.VimAutomation.Cloud    12.0.0.15940183 VMware.VimAutomation.Cloud    6.5.1.5375799 VMware.VimAutomation.Common   6.5.1.5335010

The beauty of this method is, it will install dependent modules as well.

Offline Method

In the situation, when you don’t have an internet connection on the server, you need to download the package offline from the server or desktop having an active internet connection from PowerShell Gallery and copy the package to the offline server.

You can download the package from PowerShell gallery https://www.powershellgallery.com/ and for this example search for the package “Vmware.PowerCLI” and if the package exists, you will get the package name.

When you click on this package, you will get the Manual download tab as below.

The package you download will be in the Nupkg format (Nuget Package). This package is ZIP format file and some browsers like Internet Explorer convert it to ZIP automatically but you can rename its extension to ZIP as well. You can directly extract the Nupkg content into the folder with the 7-Zip as well. The content of the folder will be as below.

Description of the above files/folders content.

  • _rels Folder − Contains the .rels file that lists the dependencies.

  • Package folder − Contains the NuGet- Specific data.

  • [Content_Types] − Describes how NuGet Extension files work with PowerShellGet.

  • <name>.nuspec − Contains the bulk of metadata

For more details follow the article from Microsoft regarding the offline installation method.

https://docs.microsoft.com/en-us/powershell/scripting/gallery/how-to/working-withpackages/manual-download?view=powershell-7

Once you have unzipped the folder name would be like <Modulename.Version>, remove the version from that folder name, and the folder name would be now the module name.

According to the article above, we need to delete the Nuget-Specific elements from the folder but we can directly copy/paste the entire unzipped folder to the Powershell module path. Below is the module path for the Powershell.

PS C:\WINDOWS\system32> $env:PSModulePath -split ';' C:\Users\admin\Documents\WindowsPowerShell\Modules C:\Program Files\WindowsPowerShell\Modules C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\ C:\Program Files\PoSHServer\modules\ C:\Windows\System32\WindowsPowerShell\v1.0\Modules

We will choose here “C:\Program Files\WindowsPowerShell\Modules” module folder and copy the unzipped folder there. Now reopen or open a new PowerShell session and check if the copied new module loaded properly and you can see that the vmware.powercli module is there.

PS C:\WINDOWS\system32> Get-Module -Name *vmware* -ListAvailable | Select Name,Version Name                            Version ----                            ------- VMware.CloudServices             12.0.0.15947289 VMware.DeployAutomation          7.0.0.15902843 VMware.DeployAutomation          6.5.1.5299608 VMware.ImageBuilder              7.0.0.15902843 VMware.ImageBuilder              6.5.1.5299608 vmware.powercli                  12.0.0.15947286 VMware.Vim                       7.0.0.15939650 VMware.VimAutomation.Cis.Core    6.5.1.5374323 VMware.VimAutomation.Cloud       12.0.0.15940183 VMware.VimAutomation.Cloud       6.5.1.5375799 VMware.VimAutomation.Common      6.5.1.5335010 VMware.VimAutomation.Core        6.5.1.5374329 VMware.VimAutomation.HA          6.0.0.5314477 VMware.VimAutomation.Hcx         12.0.0.15939647 VMware.VimAutomation.HorizonView 7.12.0.15718406 VMware.VimAutomation.HorizonView 7.1.0.5307191

This method doesn’t install the dependent module. You need to download the dependent modules and install them separately if needed.

Updated on: 2020-12-18T12:28:03+05:30

943 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements