<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: A Problem with the Microsoft Script Repository?</title>
	<atom:link href="http://www.powershellpro.com/write-host/171/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.powershellpro.com/write-host/171/</link>
	<description>Sharing the Experience</description>
	<pubDate>Fri, 21 Nov 2008 03:28:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: gary</title>
		<link>http://www.powershellpro.com/write-host/171/#comment-228</link>
		<dc:creator>gary</dc:creator>
		<pubDate>Wed, 01 Oct 2008 20:04:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/write-host/171/#comment-228</guid>
		<description>Try this script. If you run this within PowerGUI and step through each line of code as it runs, you'll find that the "write-output" and the return value of 2 all get stuffed into the variable $result.  So, $result really is assigned a system.object[] value, that contains two things (e.g. $result[0] will be the text string, and $result[1] will be the number 2.

# -----
function test() {Write-Output "A line of text.";return 2}
Write-Output "Begin"
$result = test
Write-Output "End, $result"
# -----</description>
		<content:encoded><![CDATA[<p>Try this script. If you run this within PowerGUI and step through each line of code as it runs, you&#8217;ll find that the &#8220;write-output&#8221; and the return value of 2 all get stuffed into the variable $result.  So, $result really is assigned a system.object[] value, that contains two things (e.g. $result[0] will be the text string, and $result[1] will be the number 2.</p>
<p># &#8212;&#8211;<br />
function test() {Write-Output &#8220;A line of text.&#8221;;return 2}<br />
Write-Output &#8220;Begin&#8221;<br />
$result = test<br />
Write-Output &#8220;End, $result&#8221;<br />
# &#8212;&#8211;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fedor</title>
		<link>http://www.powershellpro.com/write-host/171/#comment-219</link>
		<dc:creator>Fedor</dc:creator>
		<pubDate>Fri, 19 Sep 2008 16:50:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/write-host/171/#comment-219</guid>
		<description>Here is a nice :) touch to the above.
Place your script into a function, let's call it TIME. Create a simple Menu that depending on the response executes the function:

 Press 1 &#60;-- To output the results to the console/screen
 Press 2 &#60;-- To output the results to a file
$Response = Read-Host "Please make your selection "

If ($Response -eq 1) {TIME}
else {TIME &#124; out-file -filepath "C:\LocalTime.txt" -append} 

#You are Done!</description>
		<content:encoded><![CDATA[<p>Here is a nice <img src='http://www.powershellpro.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> touch to the above.<br />
Place your script into a function, let&#8217;s call it TIME. Create a simple Menu that depending on the response executes the function:</p>
<p> Press 1 &lt;&#8211; To output the results to the console/screen<br />
 Press 2 &lt;&#8211; To output the results to a file<br />
$Response = Read-Host &#8220;Please make your selection &#8221;</p>
<p>If ($Response -eq 1) {TIME}<br />
else {TIME | out-file -filepath &#8220;C:\LocalTime.txt&#8221; -append} </p>
<p>#You are Done!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shravan</title>
		<link>http://www.powershellpro.com/write-host/171/#comment-214</link>
		<dc:creator>shravan</dc:creator>
		<pubDate>Tue, 16 Sep 2008 14:26:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/write-host/171/#comment-214</guid>
		<description>how do i obtain the redirected drive using powershell scripts</description>
		<content:encoded><![CDATA[<p>how do i obtain the redirected drive using powershell scripts</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://www.powershellpro.com/write-host/171/#comment-103</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Sat, 03 May 2008 21:38:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/write-host/171/#comment-103</guid>
		<description>Of course, using Write-Output doesn't allow colors, so one of the attractive features of PowerShell is lost (I'd ~like~ to use it to call attention to certain results, but now I can't since I also want to redirect results to a file).  

Compound this with Functions' behavior of "returning" all output as a result unless it's sent to Write-Host, and we get into an overly difficult game of Twister....</description>
		<content:encoded><![CDATA[<p>Of course, using Write-Output doesn&#8217;t allow colors, so one of the attractive features of PowerShell is lost (I&#8217;d ~like~ to use it to call attention to certain results, but now I can&#8217;t since I also want to redirect results to a file).  </p>
<p>Compound this with Functions&#8217; behavior of &#8220;returning&#8221; all output as a result unless it&#8217;s sent to Write-Host, and we get into an overly difficult game of Twister&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse Hamrick</title>
		<link>http://www.powershellpro.com/write-host/171/#comment-68</link>
		<dc:creator>Jesse Hamrick</dc:creator>
		<pubDate>Fri, 07 Mar 2008 21:42:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/write-host/171/#comment-68</guid>
		<description>Don,
Thanks for providing more information on once the Write-Host cmdlet ouputs to the screen, there is no data to enter the pipeline.
Just want to tweak your examples as I'm getting a datatype error with example 1.

Example 1.
[code]Write-Output (1, 2, 3) &#124; Where {$_ -gt 1}[/code]

Example 2.
[code]Write-Host (1, 2, 3) &#124; Where {$_ -gt 1}[/code]</description>
		<content:encoded><![CDATA[<p>Don,<br />
Thanks for providing more information on once the Write-Host cmdlet ouputs to the screen, there is no data to enter the pipeline.<br />
Just want to tweak your examples as I&#8217;m getting a datatype error with example 1.</p>
<p>Example 1.</p>
<div class="codesnip-container" >Write-Output (1, 2, 3) | Where {$_ -gt 1}</div>
<p>Example 2.</p>
<div class="codesnip-container" >Write-Host (1, 2, 3) | Where {$_ -gt 1}</div>
]]></content:encoded>
	</item>
	<item>
		<title>By: Don Jones</title>
		<link>http://www.powershellpro.com/write-host/171/#comment-67</link>
		<dc:creator>Don Jones</dc:creator>
		<pubDate>Fri, 07 Mar 2008 19:09:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/write-host/171/#comment-67</guid>
		<description>Some background: Write-Host sends objects directly to Out-Host, which displays them on the screen. There's no change for redirection to step in.

Write-Output, on the other hand, writes objects to the pipeline. Normally, the pipeline ends inn Out-Default - which redirects objects to Out-Host and thus displays them on-screen. However, if you do something like

Dir &#124; Out-File c:\dir.txt

The objects go from the pipeline into a file. Because most of the Out-* cmdlets don't emit objects, the pipeline after Out-File is empty, so nothing is displayed on-screen. 

There IS a lot of misunderstanding about the difference between Write-Host and Write-Output. A simple example is:

Write-Output 1,2,3 &#124; Where { $_ -gt 1 }
Write-Host 1,2,3 &#124; Where { $_ -gt 1 }

In the first, three objects are dumped into the pipeline. Where-Object filters out the first, leaving two to go on to Out-Default and then Out-Host. So you see 2 and 3. In the second example, three objects are written to Out-Host. There's nothing in the pipeline, so Where-Object has nothing to filter. Nothing goes to Out-Default. So you see 1, 2, and 3 - because they bypassed the pipeline and went directly to the screen.

About the only way to "redirect" Write-Host is to use Start-Transcript and Stop-Transcript, since they explicitly grab everything that appears on-screen, no matter how it gets there.</description>
		<content:encoded><![CDATA[<p>Some background: Write-Host sends objects directly to Out-Host, which displays them on the screen. There&#8217;s no change for redirection to step in.</p>
<p>Write-Output, on the other hand, writes objects to the pipeline. Normally, the pipeline ends inn Out-Default - which redirects objects to Out-Host and thus displays them on-screen. However, if you do something like</p>
<p>Dir | Out-File c:\dir.txt</p>
<p>The objects go from the pipeline into a file. Because most of the Out-* cmdlets don&#8217;t emit objects, the pipeline after Out-File is empty, so nothing is displayed on-screen. </p>
<p>There IS a lot of misunderstanding about the difference between Write-Host and Write-Output. A simple example is:</p>
<p>Write-Output 1,2,3 | Where { $_ -gt 1 }<br />
Write-Host 1,2,3 | Where { $_ -gt 1 }</p>
<p>In the first, three objects are dumped into the pipeline. Where-Object filters out the first, leaving two to go on to Out-Default and then Out-Host. So you see 2 and 3. In the second example, three objects are written to Out-Host. There&#8217;s nothing in the pipeline, so Where-Object has nothing to filter. Nothing goes to Out-Default. So you see 1, 2, and 3 - because they bypassed the pipeline and went directly to the screen.</p>
<p>About the only way to &#8220;redirect&#8221; Write-Host is to use Start-Transcript and Stop-Transcript, since they explicitly grab everything that appears on-screen, no matter how it gets there.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
