Use Write-Cmdlets with Care!

There is a fundamental difference between outputting data using Write-Host and just "leaving info behind":"

Function test {
Write-Host "Result A"
"Result B"
}

When you run the function, you will get back both results, but Write-Host always directly writes to the console. As such, So you cannot store this result in a variable to process it later.

test
Result A
Result B
$a = test
Result A
$a
Result B

Twitter This Tip! ReTweet this Tip!


Posted Sep 30 2010, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.