Skip to content

Rule request: AvoidUsingOutNull #2110

Open
@DrSkillIssue

Description

@DrSkillIssue

Summary of the new feature

I want PSScriptAnalyzer to flag uses of Out-Null for output suppression so that I can maintain consistent code style and potentially gain minor performance improvements.

Currently, many PowerShell scripts use | Out-Null to suppress command output, but there are alternative approaches like [void], > $null, or assignment to $null that are stylistically preferred by many developers. While the performance difference is minimal, having a consistent approach to output suppression improves code readability and maintainability.

Proposed technical implementation details (optional)

  • Rule Name: AvoidUsingOutNull
  • Severity: Information (since this is primarily a style preference)
  • Category: Style
  • Detection: Flag any pipeline that ends with | Out-Null
  • Suggested alternatives:
    • [void](command)
    • command > $null
    • $null = command
  • Example violation: Get-Process | Out-Null
  • Example fix: [void](Get-Process) or Get-Process > $null

The rule should provide informational messages suggesting these alternatives while acknowledging that this is primarily a stylistic choice rather than a critical performance issue.

What is the latest version of PSScriptAnalyzer at the point of writing

1.24.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions