I would like to set up a variable in my code that would ultimately define if I\'ll see some output or not.
\"hello\" writes to stdout
All right. Thanks to all the brainiacs here for the motivation. This answer may not be the best way to go about it, but it works!
Two things you need to understand to achieve this:
Write-Host, it won't work, you'll have to go with Write-Output.One is self explanatory, so here's how to attain #2:
Function Test-SctiptBlockParam {
Param(
$scriptblock
)
if ($debugOutput) {
Invoke-Command $scriptblock
} else {
(Invoke-Command $scriptblock) > $null
}
}
Test-SctiptBlockParam -scriptblock { Write-Output "I want to see on the STDOUT sometimes" }
Finally, here is an example of my output and code