Databases Reference
In-Depth Information
Modules
Modules are another new feature introduced in PowerShell 2.0. Before modules were available,
developers who wanted to introduce new functionality into PowerShell were required to use snap-
ins, which were created in the C# programming language, compiled, and then imported into the
PowerShell host. This was difi cult and required the assistance of an experienced C# developer to
introduce new functionality. Modules are designed to make this easier, as a module is a package that
can contain members such as cmdlets, providers, functions, variables, aliases, and so on. There are
four types of module, described in the following sections.
Script Modules
A PowerShell script that has a . PSM1 i le extension is known as a script module . Modules contain
PowerShell script that can be shared within an organization and, if required, further ai eld. Adding
advanced functions as shown in the last section enables the script author to create cmdlet-like
functionality and share it.
Script modules are the most accessible way to create a module because any valid PowerShell script
can simply be saved into a i le with a . PSM1 extension and then be used as any other module type.
Binary Modules
A binary module contains compiled .NET code and is compiled into an assembly (. dll ). This is
essentially a replacement for the snap-in functionality provided in PowerShell 1.0. The disadvantage
of using binary modules is that the assistance of an experienced C# developer was required to create
the modules. However, if signii cant intellectual property is contained within the module, this may
be the best approach because the code can be obfuscated before it is distributed.
Manifest Modules
Manifest modules are used to describe the contents of a module. They can contain the prerequisites
(PowerShell version, .NET Framework version, etc.); processing directives such as scripts; formats;
and type properties. Restrictions can be applied, such as members of the module to export. This
is useful when creating a clean API for others to share. By convention, manifest i les have a .psd1
extension, and formatting and type i les have a .psxml extension.
Dynamic Modules
Dynamic modules are created on demand using the New-Module cmdlet. These modules live in mem-
ory only for the session in which the PowerShell host is active, and because of this transient nature
they are not exposed through the Get-Module cmdlet.
Working with Modules
To identify the modules available on your system, you can use the Get-Module cmdlet with the
-ListAvailable parameter, which returns a list of all the modules that can be imported into the
session. The following example shows the SQL modules available on my system:
Search WWH ::




Custom Search