Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/instructions/pwsh.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,36 @@ function Get-ProcessedData {
}
```

## Suppressing Output

- Use `$null =` to suppress unwanted output from commands
- Avoid using `| Out-Null` as it is significantly slower
- Use `[void]` for method calls that return values you want to discard
- This is especially important in loops or performance-critical code

**Good:**

```powershell
# Suppress output from .NET method calls
$null = $list.Add($item)
$null = $collection.Remove($item)

# Alternative for methods
[void]$list.Add($item)

# Suppress output from cmdlets
$null = New-Item -Path $path -ItemType Directory
```

**Bad:**

```powershell
# Slower performance with Out-Null
$list.Add($item) | Out-Null
$collection.Remove($item) | Out-Null
New-Item -Path $path -ItemType Directory | Out-Null
```

## Pipeline

- Design functions to accept pipeline input when appropriate
Expand Down
Loading