Search code examples
powershellmodulemanifestpowershell-2.0

How to export PowerShell module aliases with a module manifest?


I have a module with multiple functions.

Since I've named them in a not-PowerShell-way I want to rename them. But as the module is already in use I want to keep the old function names.

The best way to achieve this, seems to use aliases. I already have a module manifest which states:

AliasesToExport = '*'

So I created an alias in the module with New-Alias -Name test -Value oldFunctionName.

The functions were imported as usual, but the alias was not there.

I know I can use the Export-ModuleMember in the module. But I have a manifest which already should take care of this.

So here are finally my questions:

Why are the aliases not exported through the manifest?

Is there a special place in the function itself, where I can or must define an alias? Or do I have to use the New-Alias cmdlet somewhere special?

I was thinking of something like the parameter aliases:

[parameter(Mandatory=$true, Position=0)][Alias("name","path")][String]$filename

But for functions instead.


Solution

  • 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.