Welcome to MSDN Blogs Sign in | Join | Help

Functions vs Filters

In my previous entry, I referred to Rsbohn's blog PowerShell $Profile and his function to slow down output

function slowly ($tempo=100) { process { $_; Start-Sleep -milliseconds $tempo}}

This is a good candidate for a FILTER. A filter is function that just has a process scriptblock. So you could have written his as:

filter slowly ($tempo=100) { $_; Start-Sleep -milliseconds $tempo}

Enjoy!

Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx

Published Sunday, March 04, 2007 5:13 AM by PowerShellTeam

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Functions vs Filters

Funny, I just read about FILTERs in Bruce Payette's book. Now if I can just figure out Chapter 8...

Saturday, March 10, 2007 4:17 AM by rsbohn

# re: Functions vs Filters

So uhm (I know this is late, but this is still the #1 Google hit for Functions vs Filters): _Why_ would it be better as a filter? Is it just because the filter name would let everyone know that all it has is a process block?  Or is there some actual benefit to this...

Monday, October 08, 2007 10:55 AM by Joel Bennett

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker