Skip to content

Commit fb3deaf

Browse files
Update for PR
1 parent 23e6f84 commit fb3deaf

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

.github/instructions/pwsh.instructions.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)