更新时间:2023-12-05 18:51:10
使用PSM1文件中的Export-ModuleMember
导出Alias
Export-ModuleMember -function foo -Alias bar
Steps to reproduce:
Create a TestAlias module in \WindowsPowerShell\Modules\TestAlias\TestAlias.psm1 with the following function and alias:
function foo
{ write-output 'foo' }
New-Alias -name bar -value foo
From a PowerShell session:
import-module TestAlias
bar
The term 'bar' is not recognized as the name of a cmdlet, function, script file, or operable program...
Use Export-ModuleMember
in the PSM1 file to export the Alias
Export-ModuleMember -function foo -Alias bar