René's URL Explorer Experiment


Title: Add new AvoidUsingNewObject rule by iRon7 · Pull Request #2186 · PowerShell/PSScriptAnalyzer · GitHub

Open Graph Title: Add new AvoidUsingNewObject rule by iRon7 · Pull Request #2186 · PowerShell/PSScriptAnalyzer

X Title: Add new AvoidUsingNewObject rule by iRon7 · Pull Request #2186 · PowerShell/PSScriptAnalyzer

Description: Closes #2046 PR Summary Avoid using the New-Object cmdlet to create objects as it might perform poorly. Instead, use a type initializer to construct or cast the intended object. NoteIn most cases if there isn't an automatic correction (-fix) available, the rule won't report any violation either. This is because if there isn't an automatic correction available, it generally means that there isn't a simple type-casting or type constructor that would be more efficient or has a better syntax than the using New-Object cmdlet. In other words, if e.g. the common -Verbose parameter is used, or both the parameters -ArgumentList and -Property are used, there won't be a simple type initializer available and the rule won't report any violation for the New-Object cmdlet. Nevertheless, there are still some cases where the New-Object cmdlet might be replaceable with a type initializer that would be more efficient or has a better syntax, but an automatic correction can't be provided. For example if the -ArgumentList parameter is used with a dynamic variable, the rule will report a violation, but won't be able to provide a correction (-fix), as it's not possible to determine from the AST alone whether the variable contains a single value that can be used in a type initializer, or if it contains multiple values that would require splatting. This PR replaces PR #2109 PR Checklist PR has a meaningful title Use the present tense and imperative mood when describing your changes Summarized changes Change is not breaking Make sure all .cs, .ps1 and .psm1 files have the correct copyright header Make sure you've added a new test if existing tests do not effectively test the code changed and/or updated documentation This PR is ready to merge and is not Work in Progress. If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready.

Open Graph Description: Closes #2046 PR Summary Avoid using the New-Object cmdlet to create objects as it might perform poorly. Instead, use a type initializer to construct or cast the intended object. NoteIn most cases i...

X Description: Closes #2046 PR Summary Avoid using the New-Object cmdlet to create objects as it might perform poorly. Instead, use a type initializer to construct or cast the intended object. NoteIn most cases i...

Opengraph URL: https://github.com/PowerShell/PSScriptAnalyzer/pull/2186

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:ab0d69ca-5d35-f0d4-b686-953b59c098ed
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idD9B2:2FD62:6CC65:8F191:6AFD29F5
html-safe-nonceee2b67dec4c5c27e253cf0c0e4e81c872c403a8f0e736831430ab9c8557c108e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOUIyOjJGRDYyOjZDQzY1OjhGMTkxOjZBRkQyOUY1IiwidmlzaXRvcl9pZCI6IjMwNDg3NDQzNDYwMTEzODAyMTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac46e2579bcc14483c7235505dbff9b26d5c97949ba002d3c9424c37b2b8cd7241
hovercard-subject-tagpull_request:3833562643
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
twitter:imagehttps://avatars.githubusercontent.com/u/8080834?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/8080834?s=400&v=4
og:image:altCloses #2046 PR Summary Avoid using the New-Object cmdlet to create objects as it might perform poorly. Instead, use a type initializer to construct or cast the intended object. NoteIn most cases i...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None065128366c233a9d57ff68ab6c96e25b99dd1b0ab70d23b70873d3dd6b5e4f19
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/PowerShell/PSScriptAnalyzer git https://github.com/PowerShell/PSScriptAnalyzer.git
octolytics-dimension-user_id11524380
octolytics-dimension-user_loginPowerShell
octolytics-dimension-repository_id33149177
octolytics-dimension-repository_nwoPowerShell/PSScriptAnalyzer
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id33149177
octolytics-dimension-repository_network_root_nwoPowerShell/PSScriptAnalyzer
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release941021edf0c2ec58298f4a2c8f27ae507d129c92
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPSScriptAnalyzer%2Fpull%2F2186%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2FPowerShell%2FPSScriptAnalyzer%2Fpull%2F2186%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=PowerShell%2FPSScriptAnalyzer
Reloadhttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Reloadhttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Reloadhttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
PowerShellhttps://github.com/PowerShell
PSScriptAnalyzerhttps://github.com/PowerShell/PSScriptAnalyzer
Codehttps://github.com/PowerShell/PSScriptAnalyzer
Issues407 (407)https://github.com/PowerShell/PSScriptAnalyzer/issues
Pull requests34 (34)https://github.com/PowerShell/PSScriptAnalyzer/pulls
Discussionshttps://github.com/PowerShell/PSScriptAnalyzer/discussions
Actionshttps://github.com/PowerShell/PSScriptAnalyzer/actions
Projectshttps://github.com/PowerShell/PSScriptAnalyzer/projects
Wikihttps://github.com/PowerShell/PSScriptAnalyzer/wiki
Security and qualityhttps://github.com/PowerShell/PSScriptAnalyzer/security
Insightshttps://github.com/PowerShell/PSScriptAnalyzer/insights
Sign up for GitHub https://github.com/signup?return_to=%2FPowerShell%2FPSScriptAnalyzer%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2FPowerShell%2FPSScriptAnalyzer%2Fissues%2Fnew%2Fchoose
iRon7https://github.com/iRon7
PowerShell:mainhttps://github.com/PowerShell/PSScriptAnalyzer/tree/main
iRon7:#2046-AvoidUsingNewObjecthttps://github.com/iRon7/PSScriptAnalyzer/tree/%232046-AvoidUsingNewObject
Conversation 45 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186
Commits 9 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/commits
Checks 4 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/checks
Files changed https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Add new AvoidUsingNewObject rule https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#top
Show all changes 9 commits https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
e14adb2 Add new AvoidUsingNewObject rule to flag usage of New-Object cmdlet a… iRon7 Jun 9, 2026 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/commits/e14adb2deb691c6b36ba6156ffae8b4e89e9e8c2
0aad726 Implemented feedback from CoPilot iRon7 Jun 10, 2026 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/commits/0aad726963f6b89c11943a4a44c28c63af979e33
d9e0e6b Implemented more CoPilot suggestions iRon7 Jun 10, 2026 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/commits/d9e0e6b59df40e33963fd9a4829b9ace7220de9b
e061335 Resolved minor the grammar iRon7 Jun 10, 2026 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/commits/e061335231b26f5f55d7dfcdf470a70a535e7743
12b4bb1 Merge branch 'main' into #2046-AvoidUsingNewObject iRon7 Jun 10, 2026 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/commits/12b4bb1298b98e607ab027fc6d5326bdff038ef5
b9fd316 Synced my fork and resolved "Cannot determine line endings" in PS5 iRon7 Jun 23, 2026 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/commits/b9fd31609d955628e61d545a5a461afee38e1420
6b2ca61 Merge branch 'main' into #2046-AvoidUsingNewObject iRon7 Sep 13, 2026 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/commits/6b2ca610b7a1729aa89db779a715b6ee4ef9e9c4
2066057 Merge branch 'main' into #2046-AvoidUsingNewObject iRon7 Sep 15, 2026 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/commits/2066057ec96deb52cc059845a7b23e4a2ce5e122
cb003e6 Updated rule documentation iRon7 Sep 17, 2026 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/commits/cb003e6cbe438b9aee9ee71c7e5a08dc8cb44d9a
Clear filters https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
AvoidUsingNewObject.cs https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#diff-3fe5a9ec4764f42316c1e019b8df3c803fdf389cb6c521f039c0627564e8081b
Strings.resx https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#diff-dcff94e6a5c5ee1dc9226dea0752aba08f8f1f53020b4a0e67f1ac944036b8c3
AvoidUsingNewObject.tests.ps1 https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#diff-02527675bee8420e06f1eeb6799d4a5b66b84c632afb63176f79a94ab54a0c6b
AvoidUsingNewObject.md https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#diff-c049dfb94a530f43a80c15643d66eff05c523f2413c184aaf13b22312cb30087
README.md https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#diff-aa3ee3522a3ec73c6f36f2fe020f02ee8517299d57cfe67d99ff0efd2038a0d5
global.json https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#diff-8df3cd354bc584349d04ad5675b33c042d8b99b741b8b95af394c55e0f5001bf
https://github.com/PowerShell/PSScriptAnalyzer/blob/main/.github/CODEOWNERS#L2
Rules/AvoidUsingNewObject.cshttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#diff-3fe5a9ec4764f42316c1e019b8df3c803fdf389cb6c521f039c0627564e8081b
View file https://github.com/PowerShell/PSScriptAnalyzer/blob/cb003e6cbe438b9aee9ee71c7e5a08dc8cb44d9a/Rules/AvoidUsingNewObject.cs
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/{{ revealButtonHref }}
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
iRon7https://github.com/iRon7
Jun 10, 2026https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#r3386846678
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
https://github.com/PowerShell/PSScriptAnalyzer/blob/main/.github/CODEOWNERS#L2
Rules/Strings.resxhttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#diff-dcff94e6a5c5ee1dc9226dea0752aba08f8f1f53020b4a0e67f1ac944036b8c3
View file https://github.com/PowerShell/PSScriptAnalyzer/blob/cb003e6cbe438b9aee9ee71c7e5a08dc8cb44d9a/Rules/Strings.resx
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/{{ revealButtonHref }}
https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#diff-dcff94e6a5c5ee1dc9226dea0752aba08f8f1f53020b4a0e67f1ac944036b8c3
https://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files#diff-dcff94e6a5c5ee1dc9226dea0752aba08f8f1f53020b4a0e67f1ac944036b8c3
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
Please reload this pagehttps://github.com/PowerShell/PSScriptAnalyzer/pull/2186/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.