title: How to to use .LastWriteTime and (Get-Date).Month to move data into a new Year/Month Folder Structure
body: <p>I am fairly new to powershell and have been tasked at cleaning up an archive server. I am trying to create a script to move files into a Year\Month folder structure by looking at it's LastWriteTime in Powershell.</p>
  
  <p>I have the below however I do not know how to get it to look at the month the file was edited?</p>
  
  <pre><code>$Path = "D:\Data"
  $NewPath = "D:\ArchiveData"
  $Year = (Get-Date).Year
  $Month = (Get-Date).Month
  
  New-Item $NewPath\ -name $CurrentYear -ItemType Directory
  New-Item $NewPath\$Year -Name $Month -ItemType Directory
  Get-ChildItem -path $Path | Where-Object {$_.LastWriteTime -Contains (Get-Date).month} | Move-Item -Destination "$NewPath\$Year\$Month"
  </code></pre>
  
  <p>Any ideas of how I could do this would be appreciated?</p>
  
  <p>Thanks</p>