I am learning PowerShell recently, and found a behavior that I cannot understand. Let me explain in 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) {
#do nothing
}
It is strange when func1 is called directly, it can output message as expected, but if put inside "if" statement, it will not. See output as below:
*** 1. run alone ****
output from func1()
output from func2()
output from func3()
True
*** 2. run inside if ****
You can see it's empty. Why is that, and how can I enable the output like the first example? Thanks!