Skip to content

The Default PowerShell Constructor #12605

@iRon7

Description

@iRon7

Type of issue

Missing information

Feedback

In my opinion, the feature:

The hashtable syntax only works for classes that have a default constructor that doesn't expect any parameters. It creates an instance of the class with the default constructor and then assigns the key-value pairs to the instance properties. If any key in the hashtable isn't a valid property name, PowerShell raises an error.

deserves a beter name than hashtable syntax, considering that this feature include more than a "hashtable syntax":

I am not native English, but I think something like the Default PowerShell Constructor would better cover the context.
A result of this feature is that you could use a "hashtable syntax" during design-time to pre-populate its properties

From my view, this feature is not known/understood enough resulting in PowerShell scripters designing there own custom constructors (which less functionality and consistency as e.g. error messages) or even functions around the class/instance to populate the related properties.

Page URL

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_classes?view=powershell-7.5

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.5/Microsoft.PowerShell.Core/About/about_Classes.md

Author

@sdwheeler

Platform Id

b1fb7f15-4113-8097-756b-806c3754b04a

Document Id

9bdef14d-66f7-ee94-2ab9-e16bd6bc751e

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions