Repository navigation
Open
Labels
Issue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeWG-Languageparser, language semantics
Description
Steps to reproduce
Currently when classes are defined within a module it seems the best way to access them us with the following.
using module ModuleName
[Foo]::new()
Get-Module ModuleNameExpected behavior
Like other module members (functions, cmdlets, variables, aliases, etc) it would be helpful to be able to declare classes and export them as module members. Module manifests could have a section for this.
ClassesToExport = @()Using them would feel more in line with how the rest of the language works. With the current implementation I find myself creating C# classes and importing the .cs file with Add-Type.
Environment data
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.1
PSEdition Core
GitCommitId v6.0.1
OS Microsoft Windows 10.0.15063
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.15063.909
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.15063.909
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1Reacted by Keith Hill, Mark Kraus, Rock Arruda, banzai_brooks, Michael Klement, aislinnwalters, Chris Trujillo, Jeremy McGee, Shawn, Chris Kuech and 3 more
Reacted by banzai_brooks
Metadata
Metadata
Assignees
Labels
Issue-Enhancementthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeWG-Languageparser, language semantics
Activity
iSazonov commentedon Mar 2, 2018
Dup #4112
rockarruda commentedon Mar 2, 2018
Ilya (@iSazonov) This reads more of a feature request to me rather than a bug report.
iSazonov commentedon Mar 2, 2018
It related with how we plan to design class visibility (public/private).
BrucePay commentedon Mar 13, 2018
In PowerShell today, all public types are global. For example, when you import a binary module all of the public types defined in that assembly are globally visible in their declared namespaces. PowerShell classes work the same way. All types (classes) defined in a module are global, namespace qualified by the module name. (Side note: using
Add-Typewithout namespace qualification is bad idea when creating reusable code as the types will be created in the top level namespace so your [foo] and my [foo] will collide.)There is a plan to support type name aliases with the
usingstatement to simplify some scenarios. That said, making PowerShell types work differently from the rest of .NET seems undesirable. (I supposed Export-Type could just export type name aliases into the context where the module is being imported.)WRT the private type comment, remember how the debugger works - it's just PowerShell. If a type is not accessible from PowerShell, it's not accessible from the debugger either (which is why we have hidden rather than private members).
adrian-andersson commentedon May 10, 2019
Bumping this issue
Can we also have the same for ENUMS, and REQUIREDRUNTIMES
User1785604260 commentedon Mar 26, 2023
I just stumbled upon a really easy way to export PowerShell classes from modules:
I add that at the bottom of my module where I have a PSUtils class defined, and now everything works just the way I've always wanted. Import-Module and #Requires -Modules work as-is, and my code that requires the class available at parse time also works. No more slow and limited "using module" needed!
Obviously this is still just a workaround to missing functionality, but it seems to do everything I need in the meantime.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 16, 2023
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.
microsoft-github-policy-service commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.
gabriel-vanca commentedon Jul 18, 2026
Any progress on this?