Skip to content

Instantly share code, notes, and snippets.

@ChaseFlorell
Created June 12, 2015 17:45
Show Gist options
  • Save ChaseFlorell/66507a3ec5c8702a1184 to your computer and use it in GitHub Desktop.
Save ChaseFlorell/66507a3ec5c8702a1184 to your computer and use it in GitHub Desktop.
Powershell Write-Output vs return
clear
function Invoke-First {
Write-Output 'if not piped, will display before Write-Host, if piped, will display after Write-Host'
Write-Host 'Writes every single time invoke-first is called, but is not piped out.'
return 'will not display unless piped or used as a return variable'
}
function Invoke-Second {
param(
[Parameter(ValueFromPipeline=$True)] [string] $val
)
Write-Host $val
}
Invoke-First
Write-Host
Invoke-First | Invoke-Second
Write-Host
$myVar = Invoke-First
$myVar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment