Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule request: AvoidNewObjectCmdlet #2046

Open
iRon7 opened this issue Dec 6, 2024 · 1 comment
Open

Rule request: AvoidNewObjectCmdlet #2046

iRon7 opened this issue Dec 6, 2024 · 1 comment

Comments

@iRon7
Copy link

iRon7 commented Dec 6, 2024

The New-Object cmdlet is basically* legacy.
Since PowerShell V3.0 (12 years ago), PowerShell supports type accelerators which perform much better, see: PowerShell scripting performance considerations / object creation.

*) Exceptions left there (e.g. with the use of the [-ComObject] <String> parameter)

Therefore I think that it makes sense to have a AvoidNewObjectCmdlet rule.

related: Avoid New-Object Hashtable #60

@iRon7
Copy link
Author

iRon7 commented Dec 16, 2024

You might also consider to link this type of rules to the #Requires -Version x.x statement.
(In case it doesn't exist in the concerned script: simply suppress the warning.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant