PowerShell / PowerShell/PSScriptAnalyzer

Rule request: `AvoidNewObjectCmdlet`

Open
#2,046 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Up for Grabs
Dominant language
C#
Stars
2.2k
Forks
414
Avg merge
13h 1m
Merged PRs (30d)
2

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the linked PowerShell documentation on object creation and the related “Avoid New-Object Hashtable” issue. Compare the proposed rule with existing PSScriptAnalyzer rule patterns and determine how the ComObject exception should be handled. Done means the rule’s scope and exceptions are agreed and covered by implementation tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.