How to export PowerShell module aliases with a module manifest? How to export PowerShell module aliases with a module manifest? powershell powershell

How to export PowerShell module aliases with a module manifest?


There does not seem to be the solution I am looking for.

So I had to use Export-ModuleMember

Export-ModuleMember -Function * -Alias *

At first I just used the parameter "Alias" as the Functions were supposed to be exported by the manifest (FunctionsToExport = "*"), but then just the aliases were actually exported.

So make sure that you export everything you want to be exported with the Export-ModuleMember cmdlet.


Adding -Scope Global to the New-Alias command seems to do the trick.

New-Alias -Name test -Value oldFunctionName -Scope Global

While I was trying this, I noticed something that surprised me. I have a function in a module whose purpose is to create aliases. I was surprised to see that when I use this function (after the module has been imported) the aliases it creates are associated with the module. If I remove the module, all of the aliases I created with this function go away too.


If you look at:

get-help New-ModuleManifest -full

For -AliasesToExport you can see the following:

-AliasesToExport <string[]>Specifies the aliases that the module exports. Wildcards are permitted.You can use this parameter to restrict the aliases that are exported by the module. It can remove aliases from the list of exported aliases, but it cannot add aliases to the list.If you omit this parameter, New-ModuleManifest creates an AliasesToExport key with a value of * (all), meaning that all aliases that are exported by the module are exported by the manifest.

I may be wrong, but in my understanding -AliasesToExport may be used to restrict an exported alias, but the sentence "New-ModuleManifest creates an AliasesToExport key with a value of * (all), meaning that all aliases that are exported by the module are exported by the manifest" means for me that you have to export the alias in your module.