PowerShell: Moving files into subfolder based on date

A script to move files from one directory to another and ordering them in subdirectory in the destination folder. The subdirectory name is bases on the date of the file, thus ordering all files with the same date in the same subdirectory. In the example below, only the XML files will be moved

$SourceDir = "C:Folder1"
$DestinationDir = "D:Folder2"

$files = get-childitem $SourceDir *.xml
foreach ($file in $files) 
{
$Directory = $DestinationDir + "" + $file.CreationTime.Date.ToString('dd-MM-yyyy')
if (!(Test-Path $Directory))
	{
	New-Item $directory -type directory
	}
	Move-Item $file.fullname $Directory

}

leave your comment