Basics of Modules in Powershell

A Module is a set of Powershell functionalities grouped together which can be shared across, installed and reused.
Typically Microsoft publishes different modules for each of its products (Example: Azure, Active Directory, SQL, etc…)
A module can technically be only a script stored in a .psm1 file but following are different type of files you can see in a module.

Module Components and Types:
1. Some sort of code file – usually either a PowerShell script or a managed cmdlet assembly.
2. Anything else that the above code file may need, such as additional assemblies, help files, or scripts.
3. A manifest file that describes the above files, as well as stores metadada such as author and versioning information..
4. A directory that contains all of the above content, and is located where PowerShell can reasonably find it.

Script Modules
As the name implies, a script module is a file (.psm1) that contains any valid Windows PowerShell code.

Binary Modules
A binary module is a .NET Framework assembly (.dll) that contains compiled code, such as C#.

Manifest Modules
A manifest module is a module that uses a manifest file to describe all of its components, but doesn’t have any sort of core assembly or script.

Dynamic Modules
A dynamic module is a module is not loaded from, or saved to, a file. Instead, they are created dynamically by a script, using the New-Module cmdlet. This type of module enables a script to create a module on demand that does not need to be loaded or saved to persistent storage.

How to use modules:
• Modules needs to be downloaded or installed into the System
• Modules must be loaded to current session to use the modules (Import-Module cmdlet can be used to load a module)

Examples:
• While loading a module in which directory Powershell checks the availability of module?

$env:PSModulePath:

Powershell_Modules_1

• How to validate all modules available to load:

Get-Module –ListAvailable

Powershell_Modules_2

• How to import a module into current session

 Import-Module Azure.Storage 
#Module can also be imported by providing specific location
Import-Module –Name C:\myRandomDirectory\myModule -Verbose

Powershell_Modules_3

Reference: https://technet.microsoft.com/en-us/library/dd878324(v=VS.85).aspx

Advertisements
This entry was posted in Azure, Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s