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

$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

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