PSScriptAnalyzer icon indicating copy to clipboard operation
PSScriptAnalyzer copied to clipboard

Rule request: AvoidUsingOutNull

Open DrSkillIssue opened this issue 7 months ago • 0 comments

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

DrSkillIssue avatar Jun 15 '25 17:06 DrSkillIssue