< Back

Enable-OutputSubscriber

Sat Jan 18, 2020 9:43 pm

NAME Enable-OutputSubscriber



SYNOPSIS

Attaches a ScriptBlockOutputSubscriber to the current host interceptor, or attaches an existing

ScriptBlockOutputSubscriber object to the interceptor.





SYNTAX

Enable-OutputSubscriber [-OnWriteOutput <ScriptBlock>] [-OnWriteDebug <ScriptBlock>] [-OnWriteVerbose

<ScriptBlock>] [-OnWriteError <ScriptBlock>] [-OnWriteWarning <ScriptBlock>] [<CommonParameters>]



Enable-OutputSubscriber [-InputObject] <ScriptBlockOutputSubscriber> [<CommonParameters>]





DESCRIPTION

This cmdlet creates a new ScriptBlockOutputSubscriber object and attaches it to the current session's host

interceptor, or attaches an existing ScriptBlockOutputSubscriber object to the interceptor. When creating a new

ScriptBlockOutputSubscriber, the calling script MUST maintain a reference to the resulting object in a variable to

prevent it from being garbage collected and detached from the interceptor.



Every time a line is written to the console via the Output, Error, Warning, Verbose or Debug streams, the

corresponding script block is called. The script block will be sent a single string argument containing the line

to be written (including the trailing "`r`n" characters).



This is a generic implementation of the HostIoInterceptor / HostIoSubscriber classes that allows script writers to

develop their own logging logic rather than using the included PSLogFile class.





PARAMETERS

-OnWriteOutput <ScriptBlock>

The script block to be executed when a line of normal host output is displayed.



Required? false

Position? named

Default value null

Accept pipeline input? false

Accept wildcard characters? false



-OnWriteDebug <ScriptBlock>

The script block to be executed when a line of debug output is displayed.



Required? false

Position? named

Default value null

Accept pipeline input? false

Accept wildcard characters? false



-OnWriteVerbose <ScriptBlock>

The script block to be executed when a line of verbose output is displayed.



Required? false

Position? named

Default value null

Accept pipeline input? false

Accept wildcard characters? false



-OnWriteError <ScriptBlock>

The script block to be executed when a line of error output is displayed.



Required? false

Position? named

Default value null

Accept pipeline input? false

Accept wildcard characters? false



-OnWriteWarning <ScriptBlock>

The script block to be executed when a line of warning output is displayed.



Required? false

Position? named

Default value null

Accept pipeline input? false

Accept wildcard characters? false



-InputObject <ScriptBlockOutputSubscriber>

The existing ScriptBlockOutputSubscriber object to be attached to the host interceptor.



Required? true

Position? 0

Default value

Accept pipeline input? true (ByValue)

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS

PowerShellLogging.ScriptBlockOutputSubscriber (if attaching an existing object)







OUTPUTS











NOTES











RELATED LINKS

Get-OutputSubscriber

Disable-OutputSubscriber

about_PowerShellLogging