Export-ModuleMember

Specifies the module members that are exported.

Syntax
      Export-ModuleMember [[-Function] String[]] [-Alias String[]] [-Cmdlet String[]]
         [-Variable String[]] [CommonParameters]

Key
   -Alias String[]
       The aliases that are to be exported from the script module file.
       Enter the alias names. Wildcards are permitted.
        
   -Cmdlet String[]
       The cmdlets that are to be exported from the script module file.
       Enter the cmdlet names. Wildcards are permitted.
        
       You cannot create cmdlets in a script module file, but you can import cmdlets from a binary module into a 
       script module and re-export them from the script module.
        
   -Function String[]
       The functions that are to be exported from the script module file.
       Enter the function names. Wildcards are permitted.
       You can also pipe function name strings to Export-ModuleMember.
        
   -Variable String[]
       Specifies the variables that are exported from the script module file. Enter the variable names (without a 
       dollar sign). Wildcards are permitted.

   CommonParameters:
       -Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
       -OutBuffer -OutVariable.

Export-ModuleMember specifies the module members (such as cmdlets, functions, variables, and aliases) that are exported from a script module (.psm1) file, or from a dynamic module created by using the New-Module cmdlet.
This cmdlet can be used only in a script module file or a dynamic module.

If a script module does not include an Export-ModuleMember command, the functions in the script module are exported, but the variables and aliases are not. When a script module includes Export-ModuleMember commands, only the members specified in the Export-ModuleMember commands are exported. You can also use Export-ModuleMember to suppress or export members that the script module imports from other modules.

An Export-ModuleMember command is optional, but it is a best practice. Even if the command confirms the default values, it demonstrates the intention of the module author.

Examples

Export the aliases defined in the script module, along with the functions defined in the script module:

PS C:\> Export-ModuleMember -function * -alias *

Export two aliases and two functions defined in the script module:

PS C:\> Export-ModuleMember -function Get-SS64, New-SS64 -alias gss, nss

Export only the $ss64 variable from the script module:

PS C:\> Export-ModuleMember -variable ss64

Export no members defined in the script module. This does not hide the members. Users can read and copy module members or use the call operator (&) to invoke module members that are not exported:

PS C:\> Export-ModuleMember

“If we do not find anything pleasant, at least we shall find something new” ~ Voltaire

Related PowerShell Commands:

Import-Module - Add a module to the session
New-Module - Create a new dynamic module (only in memory)
Remove-Module - Remove a module from the current session


Copyright © SS64.com 1999-2018
Some rights reserved