Skip to content

Instantly share code, notes, and snippets.

@gravejester
Created September 7, 2016 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gravejester/5a7479f4a2e753441f2266ea87519472 to your computer and use it in GitHub Desktop.
Save gravejester/5a7479f4a2e753441f2266ea87519472 to your computer and use it in GitHub Desktop.
function Invoke-StreamData {
[CmdletBinding()]
param (
[switch] $ShowWarning,
[switch] $ShowError
)
Write-Host "This is written to the host"
Write-Verbose "This is written to the verbose stream"
Write-Output "This is written to the output stream"
if ($ShowWarning) {
Write-Warning "This is written to the warning stream"
}
if ($ShowError) {
Write-Error "This is written to the error stream"
}
}
$thisWarning = $($thisVerbose = $($thisOutput = Invoke-StreamData -ErrorVariable 'ThisError' -ErrorAction SilentlyContinue -Verbose -ShowWarning -ShowError) 4>&1) 3>&1
Write-Host ''
Write-Host "Contents of the thisWarning variable: "
Write-Host $thisWarning
Write-Host ''
Write-Host "Contents of the thisVerbose variable: "
Write-Host $thisVerbose
Write-Host ''
Write-Host "Contents of the ThisError variable: "
Write-Host $ThisError
Write-Host ''
Write-Host "Contents of the thisOutput variable: "
Write-Host $thisOutput
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment