Skip to content

Invoke-SpectreScriptBlockQuietly

Description

This function invokes a script block in a background job and returns the output. It also provides an option to suppress the output even more if there is garbage being printed to stderr if using Level = Quieter.


Examples

Example 1
This example demonstrates how to use this function to suppress all output from a script block so it doesn’t break the progress bar.

Terminal window
$result = Invoke-SpectreCommandWithProgress {
param (
$Context
)
$task1 = $Context.AddTask("Starting a process that generates noise")
$task1.Increment(50)
$value = Invoke-SpectreScriptBlockQuietly -Level Quiet -Command {
Write-Output "Things..."
Write-Output "And stuff..."
Write-Error "This is an error"
Start-Sleep -Seconds 3
Write-Output "But it shouldn't break progress bar rendering"
}
$task1.Increment(50)
return $value
}
Write-SpectreHost "Result: $result"

Parameters

Command

The script block to be invoked.

TypeRequiredPositionPipelineInput
[ScriptBlock]false1false

Level

Suppresses the output by varying amounts.

Valid Values:

  • Quiet
  • Quieter
TypeRequiredPositionPipelineInput
[String]false2false

Syntax

Terminal window
Invoke-SpectreScriptBlockQuietly [[-Command] <ScriptBlock>] [[-Level] <String>] [<CommonParameters>]