Last Updated: June 08, 2016
· superboum

PowerShell: Export aliases of a module referenced by a manifest

Default behavior should be that every functions and aliases are exported. But it's a little bit more complicated

Everything works well with PowerShell 5

Given a manifest project named Foo with a Bar module. To export the alias Hello-World inside Bar, you have to follow some patterns.
First, let's see the structure of our directory :


Our module Bar :

# ./Bar.psm1
Set-Alias Hello-World Get-HelloWorld
function Get-HelloWorld {
    Write-Output "Hello World"
# If there is no Export-ModuleMember in your whole file, everything should be exported
# If you want to add one, don't forget to also export your Alias :
Export-ModuleMember -Function 'Get-HelloWorld' -Alias 'Hello-World'

Our Manifest Fille :

# ./Foo.psd1
    RootModule = 'Foo.psm1'
    # ... other parameters such as version, guid...
    # You don't need to uncomment ExportAlias or Function because the default behavior is Exporting everything
    NestedModules = @(

Our Root Module :

# ./Foo.psm1
# This file is empty

It's more complicated with PowerShell 4

With PowerShell 4, you need to add this line to Foo.psm1 (our root module) in order to export your aliases :

# ./Foo.psm1
Export-ModuleMember -Function '*' -Alias '*'

It could be a hack or not the correct way to do it. However it worked for us.

Say Thanks