title: PowerShell Filters, Where-Object, Get-ChildItem
body: <p>I currently have the following script that im running in PowerShell. I want to get a list of files in the directory of where the PS script resides, i want all files where the lastmodifieddate is more than 30 days ago and then move them. Im not sure what im doing wrong here.</p>
  
  <pre><code> param (
      [Parameter(Mandatory=$true)][string]$destinationRoot
   )
  
  $path = (Get-Item -Path ".\").FullName
  
  Get-ChildItem $path\*  -Include *.xlsx| 
  Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-30)} 
  Foreach-Object {
      $content = $path + "\" + $_.Name
  
      $year = (Get-Item $content).LastWriteTime.year.ToString()
      $monthNumber = (Get-Item $content).LastWriteTime.month
      $month = (Get-Culture).DateTimeFormat.GetMonthName($monthNumber)
  
      $destination = $destinationRoot + "\" + $year + "\" + $month 
  
      New-Item -ItemType Directory -Force -Path $destination
  
      Move-Item -Path $content -Destination $destination -force
  
  }
  </code></pre>