I have been studying PowerShell lately and have found behavior that I cannot understand. Let me clarify the code below:
function func1()
{
Write-Output "output from func1()"
func2
return $true
}
function func2()
{
Write-Output "output from func2()"
func3
}
function func3()
{
Write-Output "output from func3()"
}
Write-Output "*** 1. run alone ****"
func1
Write-Output "*** 2. run inside if ****"
if (func1) {
}
It is strange when func1 is called directly, it can display a message as expected, but if you enter the "if" statement inside, it will not. See Output as shown below:
*** 1. run alone ****
output from func1()
output from func2()
output from func3()
True
*** 2. run inside if ****
You can see it empty. Why is this, and how can I include output as the first example? Thank!
source
share