File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -515,6 +515,36 @@ function Get-ProcessedData {
515515}
516516```
517517
518+ ## Suppressing Output
519+
520+ - Use ` $null = ` to suppress unwanted output from commands
521+ - Avoid using ` | Out-Null ` as it is significantly slower
522+ - Use ` [void] ` for method calls that return values you want to discard
523+ - This is especially important in loops or performance-critical code
524+
525+ ** Good:**
526+
527+ ``` powershell
528+ # Suppress output from .NET method calls
529+ $null = $list.Add($item)
530+ $null = $collection.Remove($item)
531+
532+ # Alternative for methods
533+ [void]$list.Add($item)
534+
535+ # Suppress output from cmdlets
536+ $null = New-Item -Path $path -ItemType Directory
537+ ```
538+
539+ ** Bad:**
540+
541+ ``` powershell
542+ # Slower performance with Out-Null
543+ $list.Add($item) | Out-Null
544+ $collection.Remove($item) | Out-Null
545+ New-Item -Path $path -ItemType Directory | Out-Null
546+ ```
547+
518548## Pipeline
519549
520550- Design functions to accept pipeline input when appropriate
You can’t perform that action at this time.
0 commit comments