question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Aliases are not exported from script module by default

See original GitHub issue

Based 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mklement0commented, Apr 5, 2023

feels this is by design

So that the issue can be properly documented:

What is the design rationale? Specifically, why would dynamic modules behave differently?

0reactions
msftbot[bot]commented, Apr 6, 2023

This issue has been marked as by-design and has not had any activity for 1 day. It has been closed for housekeeping purposes.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found