无法在脚本模块中创建 PowerShell 别名 [英] Unable to create a PowerShell alias in a script module

查看:50
本文介绍了无法在脚本模块中创建 PowerShell 别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重现步骤:

使用以下函数和别名在 \WindowsPowerShell\Modules\TestAlias\TestAlias.psm1 中创建一个 TestAlias 模块:

函数 foo{ 写输出 'foo' }新别名 -name bar -value foo

来自 PowerShell 会话:

import-module TestAlias酒吧

<块引用>

术语bar"未被识别为 cmdlet、函数、脚本文件或可运行程序的名称...

解决方案

使用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

这篇关于无法在脚本模块中创建 PowerShell 别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆