SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have tried below but not getting any result back Not sure if i'm doing this well. Can i filter in the foreach or in my if statement Thanks in advance

[DateTime] $CreatedDate = $item["Created"] 
$convertedCreatedDate = $CreatedDate.ToString("yyyy-MM-dd")
$today = (Get-Date).AddDays(-1).ToString("yyyy-MM-dd")

foreach ($item in $list.items | where {$convertedCreatedDate -eq $today}) {

if ($list.items | where {$convertedCreatedDate -eq $today}) 

Write-Host $item["Created"] 


Write-Host $item["Created"] 

share|improve this question
C'mmon guys no one can help me with this – Patrick Feb 10 '11 at 3:53

Yes. You can filter in either or both the foreach statement and/or the if statement. You don't define $list in your question so I can only guess at what you're shooting for. It looks like you're trying to select items created in the last day from the collection in $list.Items. If so, this should get that job done:

$list.Items | 
    where { ([DateTime]::Now - [DateTime]$item["Created"]).TotalDays -lt 1 }

To perform some operation on each of those returned items add a foreach to the end of the pipeline:

$list.Items | 
    where { ([DateTime]::Now - [DateTime]$item["Created"]).TotalDays -lt 1 }
    foreach {
        # do something with $_ here

Update your question with how you define $list and I'll verify my answer if necessary.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.