且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法在脚本模块中创建 PowerShell 别名

更新时间: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