Skip to content

Conversation

@MariusStorhaug
Copy link
Member

The PowerShell style guidelines now include comprehensive guidance on suppressing unwanted output from commands and methods. This addition helps developers choose the most performant approach when they need to discard function or method return values.

Suppressing Output Section

A new section has been added to the PowerShell style guidelines (pwsh.instructions.md) that provides clear guidance on:

  • Using $null = for best performance - The recommended approach for suppressing output from both cmdlets and .NET method calls
  • Using [void] as an alternative - Another valid option specifically for method calls that return values
  • Avoiding | Out-Null - Explicitly noting that this approach has significantly slower performance and should be avoided

The section includes practical examples showing both correct and incorrect usage patterns, making it easy for developers to follow the best practices.

Performance Impact

This guidance is especially important in performance-critical code and loops, where the overhead of | Out-Null can accumulate and cause noticeable slowdowns. By using $null = or [void], developers can ensure their scripts run efficiently.

@MariusStorhaug MariusStorhaug self-assigned this Oct 6, 2025
@MariusStorhaug MariusStorhaug marked this pull request as ready for review October 6, 2025 19:53
@MariusStorhaug MariusStorhaug requested a review from a team as a code owner October 6, 2025 19:53
Copilot AI review requested due to automatic review settings October 6, 2025 19:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive guidance on suppressing unwanted output in PowerShell to the style guidelines. The addition addresses performance concerns by recommending the most efficient methods for discarding function and method return values.

  • Added a new "Suppressing Output" section to the PowerShell style guidelines
  • Provides clear recommendations for using $null = and [void] over | Out-Null
  • Includes practical examples showing correct and incorrect usage patterns

@MariusStorhaug MariusStorhaug merged commit 4fe1d90 into main Oct 6, 2025
64 of 68 checks passed
@MariusStorhaug MariusStorhaug deleted the patch/pwsh-instructions-suppress-output branch October 6, 2025 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Docs]: Add suppressing output guidance to PowerShell style guidelines

2 participants