🩹 [Docs]: Add suppressing output guidance to PowerShell style guidelines #225
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.