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)

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



• How to validate all modules available to load:

Get-Module –ListAvailable

# If you are not able to see the modules you are looking for, add module path PSModulePath 
$env:PSModulePath = $env:PSModulePath + ";c:\ModulePath"


• 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
Import-Module C:\mssql\dbatools\dbatools.psd1


Reference: PSModulePath changes: Ref:

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: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s