Aliases are not exported from script module by default
See original GitHub issueBased on the current description of Export-ModuleMember
, aliases and functions should be exported by default from any script module that does not explicitly invoke Export-ModuleMember
. As you can see from the scenario below, that is not the case for script modules that do not have a manifest.
Steps to reproduce
nmo -name A {
function Test-A {
[CmdletBinding()]
[Alias('ta')]
param()
"'$($PSCmdlet.MyInvocation.MyCommand.Name)' was invoked."
}
} | ipmo
nmo -name B {
function Test-B {
[CmdletBinding()]
param()
"'$($PSCmdlet.MyInvocation.MyCommand.Name)' was invoked."
}
New-Alias tb Test-B
} | ipmo
ta
tb
Expected behavior
'Test-A' was invoked.
'Test-B' was invoked.
Actual behavior
ta : The term 'ta' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ ta
+ ~~
+ CategoryInfo : ObjectNotFound: (ta:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
tb : The term 'tb' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ tb
+ ~~
+ CategoryInfo : ObjectNotFound: (tb:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Environment data
Name Value
---- -----
PSVersion 6.2.1
PSEdition Core
GitCommitId 6.2.1
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Note that this issue is not a regression. It exists in Windows PowerShell 5.1 as well.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Unable to create a PowerShell alias in a script module
By default, Windows PowerShell modules only export commands (functions or cmdletS), and not variables or aliases.
Read more >Export-ModuleMember (Microsoft.PowerShell.Core)
This command exports three aliases and three functions defined in the script module. You can use this command format to specify the names...
Read more >Exported alias autoloading from PSM1 module not working
My understanding (and experience of PowerShell v5) is that Modules (.psm1 files) in the Modules\ folder are automatically loaded (unless ...
Read more >Export-Alias - PowerShell
By default, Export-Alias overwrites files without warning, unless the read-only or hidden attribute is set or the NoClobber parameter is used in the...
Read more >Using Import aliases in JavaScript | by Greg Byrne | DailyJS
You can alias the import using as : import { Something1 as MySomething } from "my-module.js". For importing default exports, e.g.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
So that the issue can be properly documented:
What is the design rationale? Specifically, why would dynamic modules behave differently?
This issue has been marked as by-design and has not had any activity for 1 day. It has been closed for housekeeping purposes.