I want to backup all files on a volume that have changed in the past 24 hours. I want the backup folder to keep the folder structure of the original. I find that when I test my current script, the folders are all placed in root.
$today = Get-Date -UFormat "%Y-%m-%d"
$storage="D:\"
$backups="E:\"
$thisbackup = $backups+$today
New-Item -ItemType Directory -Force -Path $thisbackup
foreach ($f in Get-ChildItem $storage -recurse)
{
if ($f.LastWriteTime -lt ($(Get-Date).AddDays(-1)))
{
Copy-Item $f.FullName -Destination $thisbackup -Recurse
}
}
Write-Host "The backup is complete"
It also seems to be copying ALL files in these folders.
Can I get some assistance on this?