Contact Info

Crumbtrail

ActiveXperts.com » Administration » Powershell » Powershell 3.0 » New-Module

New-Module - Powershell 3.0 CmdLet

ActiveXperts Network Monitor ships with integrated Powershell scripts to monitor complex network. The scripts run out of the box
Download the ActiveXperts Network Monitor FREE version now »

New-Module

Short description
Creates a new dynamic module that exists only in memory.

Syntax
New-Module [-ScriptBlock] <ScriptBlock> [-ArgumentList <Object[]>] [-AsCustomObject] [-Cmdlet <String[]>] [-Function <S
tring[]>] [-ReturnResult] [<CommonParameters>]
New-Module [-Name] <String> [-ScriptBlock] <ScriptBlock> [-ArgumentList <Object[]>] [-AsCustomObject] [-Cmdlet <String[
]>] [-Function <String[]>] [-ReturnResult] [<CommonParameters>]





Description
The New-Module cmdlet creates a dynamic module from a script block. The members of the dynamic module, such as function
s and variables, are immediately available in the session and remain available until you close the session.


Like static modules, by default, the cmdlets and functions in a dynamic module are exported and the variables and alias
es are not. However, you can use the Export-ModuleMember cmdlet and the parameters of New-Module to override the defaul
ts.


You can also use the AsCustomObject parameter of the New-Module cmdlet to return the dynamic module as a custom object.
 The members of the modules, such as functions, are implemented as script methods of the custom object instead of being
 imported into the session.


Dynamic modules  exist only in memory, not on disk. Like all modules, the members of dynamic modules run in a private m
odule scope that is a child of the global scope. Get-Module cannot get a dynamic module, but Get-Command can get the ex
ported members.


To make a dynamic module available to Get-Module, pipe a New-Module command to Import-Module, or pipe the module object
 that New-Module returns to Import-Module. This action adds the dynamic module to the Get-Module list, but it does not 
save the module to disk or make it persistent.