I have a folder that contains subfolders each with many excel spreadsheet. I am trying to get powershell to search through the subdirectories then move all the xls file with the same creation date into a new folder of that creation date. I am close I think here is my code. What is happening is that it only looks at file in "reporting" and not the subfolders of "reporting".
Get-ChildItem "c:\users\username\documents\reporting\*.xls" -Recurse | foreach {
$x = $_.LastWriteTime.ToShortDateString()
$new_folder_name = Get-Date $x -Format yyyy.MM.dd
$des_path = "c:\users\username\documents\$new_folder_name"
if (test-path $des_path){
move-item $_.fullname $des_path
} else {
new-item -ItemType directory -Path $des_path
move-item $_.fullname $des_path
}
}