🩹 [Docs]: Add suppressing output guidance to PowerShell style guidelines#225
Merged
MariusStorhaug merged 1 commit intomainfrom Oct 6, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:$null =for best performance - The recommended approach for suppressing output from both cmdlets and .NET method calls[void]as an alternative - Another valid option specifically for method calls that return values| Out-Null- Explicitly noting that this approach has significantly slower performance and should be avoidedThe 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-Nullcan accumulate and cause noticeable slowdowns. By using$null =or[void], developers can ensure their scripts run efficiently.