Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

PSFunction - problem with the syntax

$
0
0

Hi folks,

I grabbed a Function-Example from: get-help about_Functions.
I'm having some problems to understand that simple function. It goes like that:

function Get-NewPix
          {
              $start = Get-Date -Month 1 -Day 1 -Year 2013
              $allpix = Get-ChildItem -Path $env:UserProfile\*.jpg -Recurse 
              $allpix | where {$_.LastWriteTime -gt $Start}
          }    
Get-NewPix

I do understand what the 3 line of code is for, but I don't understand why it's in a separate line? It's because the code in the 2-nd line is broken in the new (3-rd) line?
And why the function doesn't work (gets no results) when I write:


function Get-NewPix
          {
              $start = Get-Date -Month 1 -Day 1 -Year 2013
              $allpix = Get-ChildItem -Path $env:UserProfile\*.jpg -Recurse | where {$_.LastWriteTime -gt $Start}
          }    
Get-NewPix

Thanks for your help.

Pruclot



Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images