<?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: PowerShell Functions and Filters - The basics</title>
	<atom:link href="http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.powershellpro.com</link>
	<description>Sharing the Experience</description>
	<pubDate>Wed, 07 Jan 2009 02:35:13 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.5</generator>
		<item>
		<title>By: James</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-223</link>
		<dc:creator>James</dc:creator>
		<pubDate>Mon, 29 Sep 2008 12:52:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-223</guid>
		<description>I'm playing with the following script to find files older than 1 day.

$DateToCompare = (get-date).AddDays(-1)
$logFiles = get-childitem C:\logs -recurse &#124; ? {$_.LastWriteTime -lt $DateToCompare}
foreach ($f in $logfiles){
Write-Host $f.name
}

I can send the results via email, however, I need the name and lastwritetime of each file on a new line in the variable sent to the email function.  In vb it would be something like:

foreach f in fld.files
 fileformat = fileformat &#38; vbcrlf
next
SendMail fileformat

Anyone know how this is done in PS? Cheers J</description>
		<content:encoded><![CDATA[<p>I&#8217;m playing with the following script to find files older than 1 day.</p>
<p>$DateToCompare = (get-date).AddDays(-1)<br />
$logFiles = get-childitem C:\logs -recurse | ? {$_.LastWriteTime -lt $DateToCompare}<br />
foreach ($f in $logfiles){<br />
Write-Host $f.name<br />
}</p>
<p>I can send the results via email, however, I need the name and lastwritetime of each file on a new line in the variable sent to the email function.  In vb it would be something like:</p>
<p>foreach f in fld.files<br />
 fileformat = fileformat &amp; vbcrlf<br />
next<br />
SendMail fileformat</p>
<p>Anyone know how this is done in PS? Cheers J</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gary</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-221</link>
		<dc:creator>Gary</dc:creator>
		<pubDate>Mon, 22 Sep 2008 23:34:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-221</guid>
		<description>Can someone explain this odd behavior to me? 

#---
function Test($a, $b) {Write-Host "a=$a, b=$b"}
Test("one", "two")
#---

I would have expected the above to display "a=one, b=two", but instead it displays "a=one two, b=".  Why is this?  How would I pass two strings to a function and get the results I expected?</description>
		<content:encoded><![CDATA[<p>Can someone explain this odd behavior to me? </p>
<p>#&#8212;<br />
function Test($a, $b) {Write-Host &#8220;a=$a, b=$b&#8221;}<br />
Test(&#8221;one&#8221;, &#8220;two&#8221;)<br />
#&#8212;</p>
<p>I would have expected the above to display &#8220;a=one, b=two&#8221;, but instead it displays &#8220;a=one two, b=&#8221;.  Why is this?  How would I pass two strings to a function and get the results I expected?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NetGuyDave</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-189</link>
		<dc:creator>NetGuyDave</dc:creator>
		<pubDate>Thu, 14 Aug 2008 18:38:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-189</guid>
		<description>Jesse, thanks for this excellent tutorial.  This is at the perfect level for me, just beginning. Very easy read to get started.  ...on to the next one WMI!!</description>
		<content:encoded><![CDATA[<p>Jesse, thanks for this excellent tutorial.  This is at the perfect level for me, just beginning. Very easy read to get started.  &#8230;on to the next one WMI!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesse Hamrick</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-187</link>
		<dc:creator>Jesse Hamrick</dc:creator>
		<pubDate>Wed, 13 Aug 2008 17:34:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-187</guid>
		<description>The issue you are running into is a syntax problem. You are attempting to call a FUNCTION using the syntax for calling another powershell script. Let me give you examples of how to do both:
Calling a script that lives outside the main script.
Test.ps1 code -
Write-Host "Hello World"

Caller.ps1 code -
.{.\test.ps1}

Calling a Function that lives outside the main script.
Test.ps1 code -
function Hello {Write-Host "Hello Nitin"}

Caller.ps1 code -
. .\test.ps1
Hello

Make sure you understand when you are attempting to call a script or a function within a script that live outside the main script. This tutorial talks about calling functions but you have to follow "click here to find out how" link under Example 2. Calling a Function from another script file.</description>
		<content:encoded><![CDATA[<p>The issue you are running into is a syntax problem. You are attempting to call a FUNCTION using the syntax for calling another powershell script. Let me give you examples of how to do both:<br />
Calling a script that lives outside the main script.<br />
Test.ps1 code -<br />
Write-Host &#8220;Hello World&#8221;</p>
<p>Caller.ps1 code -<br />
.{.\test.ps1}</p>
<p>Calling a Function that lives outside the main script.<br />
Test.ps1 code -<br />
function Hello {Write-Host &#8220;Hello Nitin&#8221;}</p>
<p>Caller.ps1 code -<br />
. .\test.ps1<br />
Hello</p>
<p>Make sure you understand when you are attempting to call a script or a function within a script that live outside the main script. This tutorial talks about calling functions but you have to follow &#8220;click here to find out how&#8221; link under Example 2. Calling a Function from another script file.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nitin</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-173</link>
		<dc:creator>Nitin</dc:creator>
		<pubDate>Sun, 10 Aug 2008 14:50:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-173</guid>
		<description>I wrote test.ps1 which contains following line -
function Hello-World { Write-Host "Hello World" }

Then, I wrote caller.ps1 which contains following line -
.{'.\test.ps1'}

Both the scripts are in the same folder. When I run caller.ps1 file, it does not show "Hello World" on screen.

Please tell me where I was wrong.</description>
		<content:encoded><![CDATA[<p>I wrote test.ps1 which contains following line -<br />
function Hello-World { Write-Host &#8220;Hello World&#8221; }</p>
<p>Then, I wrote caller.ps1 which contains following line -<br />
.{&#8217;.\test.ps1&#8242;}</p>
<p>Both the scripts are in the same folder. When I run caller.ps1 file, it does not show &#8220;Hello World&#8221; on screen.</p>
<p>Please tell me where I was wrong.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norman</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-153</link>
		<dc:creator>Norman</dc:creator>
		<pubDate>Tue, 15 Jul 2008 09:43:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-153</guid>
		<description>One question which I have answered by experiment is to do with the scope of variables when functions are called.  For example, what output would you expect from this:
$x = 3
function aaa {
    $x += 1
    bbb
    write-host "aaa: $x"
}
function bbb {
    $x += 1
    write-host "bbb: $x"
}
$x
aaa
$x

The answer is that when you refer to a variable in a function, you get the variable that was in scope at the function call (ie dynamic, not lexical scoping) and if you declare a variable in a function it has local scope and masks any same-name global variable.  This may seem rather arcane but you need to know these things to tell what will happen!</description>
		<content:encoded><![CDATA[<p>One question which I have answered by experiment is to do with the scope of variables when functions are called.  For example, what output would you expect from this:<br />
$x = 3<br />
function aaa {<br />
    $x += 1<br />
    bbb<br />
    write-host &#8220;aaa: $x&#8221;<br />
}<br />
function bbb {<br />
    $x += 1<br />
    write-host &#8220;bbb: $x&#8221;<br />
}<br />
$x<br />
aaa<br />
$x</p>
<p>The answer is that when you refer to a variable in a function, you get the variable that was in scope at the function call (ie dynamic, not lexical scoping) and if you declare a variable in a function it has local scope and masks any same-name global variable.  This may seem rather arcane but you need to know these things to tell what will happen!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norman</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-152</link>
		<dc:creator>Norman</dc:creator>
		<pubDate>Tue, 15 Jul 2008 09:35:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-152</guid>
		<description>@hrp2171 - If I understand PS correctly, the line "$input = get-childitem -path c:\ -recurse" assigns a huge but temporary amount of data to $input, which has to be completed before you go on to the filtering.  It would be much faster to do without the $input variable and just pipe the get-childitem directly into the where-object.</description>
		<content:encoded><![CDATA[<p>@hrp2171 - If I understand PS correctly, the line &#8220;$input = get-childitem -path c:\ -recurse&#8221; assigns a huge but temporary amount of data to $input, which has to be completed before you go on to the filtering.  It would be much faster to do without the $input variable and just pipe the get-childitem directly into the where-object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Norman</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-151</link>
		<dc:creator>Norman</dc:creator>
		<pubDate>Tue, 15 Jul 2008 09:30:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-151</guid>
		<description>Is "snap-in" just copying one text file into another one?  (Coming from a Unix environment, some of the Windows jargon is unfamiliar.)</description>
		<content:encoded><![CDATA[<p>Is &#8220;snap-in&#8221; just copying one text file into another one?  (Coming from a Unix environment, some of the Windows jargon is unfamiliar.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sanjeev</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-106</link>
		<dc:creator>sanjeev</dc:creator>
		<pubDate>Thu, 08 May 2008 14:11:19 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-106</guid>
		<description>could you please explain something about functions at runtime level. because i tried overloading the function but it is only taking the latest version and not overloading at all.
i loved the tutorial.the method and the content is just perfect</description>
		<content:encoded><![CDATA[<p>could you please explain something about functions at runtime level. because i tried overloading the function but it is only taking the latest version and not overloading at all.<br />
i loved the tutorial.the method and the content is just perfect</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hrp2171</title>
		<link>http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-97</link>
		<dc:creator>hrp2171</dc:creator>
		<pubDate>Mon, 28 Apr 2008 21:14:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.powershellpro.com/powershell-tutorial-introduction/powershell-functions-filters/#comment-97</guid>
		<description>I feel so accomplished.  I re-wrote the FindFile function just to see how much I've retained so far and this is what I came up with:

Function FindFile
{
  param($fileToFind)
  $input = get-childitem -path c:\ -recurse
  $input &#124; where-object{$_.Name -eq "$fileToFind"}
}

The first time I used the function it took a little while before $input got loaded, but the second time around, it was much quicker.

I love this stuff.  Can't wait to get into the WMI scripting.</description>
		<content:encoded><![CDATA[<p>I feel so accomplished.  I re-wrote the FindFile function just to see how much I&#8217;ve retained so far and this is what I came up with:</p>
<p>Function FindFile<br />
{<br />
  param($fileToFind)<br />
  $input = get-childitem -path c:\ -recurse<br />
  $input | where-object{$_.Name -eq &#8220;$fileToFind&#8221;}<br />
}</p>
<p>The first time I used the function it took a little while before $input got loaded, but the second time around, it was much quicker.</p>
<p>I love this stuff.  Can&#8217;t wait to get into the WMI scripting.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
