Created
June 12, 2015 17:45
-
-
Save ChaseFlorell/66507a3ec5c8702a1184 to your computer and use it in GitHub Desktop.
Powershell Write-Output vs return
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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