Copy to Clipboard
$FromPath = "C:\Users\Admin\Desktop\New folder\From"
$ToPath = "C:\Users\Admin\Desktop\New folder\To"
$FolderPrefix = "Folder-"
$Counter = 1
while( ( Test-Path "$($ToPath)\$($FolderPrefix)$($Counter)" ) -eq $true ){
$Counter++
}
Write-Host "Creating the folder $($ToPath)\$($FolderPrefix)$($Counter)"
New-item -Path "$($ToPath)\$($FolderPrefix)$($Counter)" -ItemType "directory"
robocopy /mir /xj /r:0 "$FromPath" "$($ToPath)\$($FolderPrefix)$($Counter)"
Write-Host "`r`n`r`n`r`nBackup finished!"
An example batch file to run it: Copy to Clipboard
@echo off
PowerShell.exe -ExecutionPolicy Bypass -File "C:\Users\Admin\Desktop\BackupDrive.ps1"
echo.
echo.
echo This backup has finished. You may close this window.
pause
| |
Search Keywords: Powershell |