Perpetual Backup PowerShell Script
Ok, so the batch file doesn’t work as well as a PowerShell script because the command forfiles doesn’t work well. A better script is the following PowerShell script, which you can save as a ps1 file and run it the same as a batch file (perpetually).
Here’s the PowerShell version of my perpetual backup batch file script:
while ($true){
Get-ChildItem –Path “G:\” –Recurse | Where-Object CreationTime –lt (Get-Date).AddDays(-1) | Remove-Item
$folder=((Get-Date).Year).ToString()+”_”+((Get-Date).Month).ToString()+”_”+((Get-Date).Day).ToString()+”_”+((Get-Date).Hour).ToString()+”_”+((Get-Date).Minute).ToString()+”_”+((Get-Date).Millisecond).ToString()
mkdir G:\$folder
Copy-Item C:\ G:\$folder
Timeout 60
}