Export ModuleMember - PowerShell


Overview

Export-ModuleMember exports specified members of a PowerShell module to the global session. This allows you to access these members without having to import the module explicitly.

Syntax

Export-ModuleMember [-Module] <String> [-Function] <String[]> [-Cmdlet] <String[]> [-Alias] <String[]> [-Variable] <String[]> [-Error] <ErrorRecord[]> [-ErrorAction] <ErrorAction> [-OutVariable] <String>

Options/Flags

  • -Module: Specifies the name of the module to export members from.
  • -Function: Specifies the functions to export from the module.
  • -Cmdlet: Specifies the cmdlets to export from the module.
  • -Alias: Specifies the aliases to export from the module.
  • -Variable: Specifies the variables to export from the module.
  • -Error: Exports any errors encountered during the export operation.
  • -ErrorAction: Specifies how to handle any errors encountered during the export operation.
  • -OutVariable: Assigns the exported members to a specified variable.

Examples

Export a Single Function

Export-ModuleMember -Module PowerShellGet -Function Get-Package

Export Multiple Members

Export-ModuleMember -Module Net -Function Invoke-RestMethod -Cmdlet Get-EventLog

Export All Exported Members

Export-ModuleMember -Module PSScheduledJob

Common Issues

Exported Members Not Available

Ensure the module has been imported before exporting members. If using a script, import the module using Import-Module before exporting members.

Integration

Export-ModuleMember can be combined with other PowerShell commands, such as Get-Module and Get-Member, to manage and inspect exported members.

$exportedMembers = Get-Module | Get-Member -Export
  • Import-Module
  • Get-Module
  • Get-Member